Class: Ears::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ears/configuration.rb

Overview

The class representing the global Ears configuration.

Defined Under Namespace

Classes: ConnectionNameMissing

Constant Summary collapse

DEFAULT_RABBITMQ_URL =
'amqp://guest:guest@localhost:5672'
DEFAULT_RECOVERY_ATTEMPTS =
10
DEFAULT_PUBLISHER_POOL_SIZE =
32
DEFAULT_PUBLISHER_POOL_TIMEOUT =
2
DEFAULT_PUBLISHER_CONNECTION_ATTEMPTS =
30
DEFAULT_PUBLISHER_CONNECTION_BASE_DELAY =
1
DEFAULT_PUBLISHER_CONNECTION_BACKOFF_FACTOR =
1.5
DEFAULT_PUBLISHER_MAX_RETRIES =
3
DEFAULT_PUBLISHER_RETRY_BASE_DELAY =
0.1
DEFAULT_PUBLISHER_RETRY_BACKOFF_FACTOR =
2
DEFAULT_PUBLISHER_CONFIRMS_POOL_SIZE =
32
DEFAULT_PUBLISHER_CONFIRMS_TIMEOUT =
5.0
DEFAULT_PUBLISHER_CONFIRMS_CLEANUP_TIMEOUT =
1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

rubocop:disable Metrics/MethodLength



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ears/configuration.rb', line 72

def initialize # rubocop:disable Metrics/MethodLength
  @rabbitmq_url = DEFAULT_RABBITMQ_URL
  @recovery_attempts = DEFAULT_RECOVERY_ATTEMPTS
  @publisher_pool_size = DEFAULT_PUBLISHER_POOL_SIZE
  @publisher_pool_timeout = DEFAULT_PUBLISHER_POOL_TIMEOUT
  @publisher_connection_attempts = DEFAULT_PUBLISHER_CONNECTION_ATTEMPTS
  @publisher_connection_base_delay = DEFAULT_PUBLISHER_CONNECTION_BASE_DELAY
  @publisher_connection_backoff_factor =
    DEFAULT_PUBLISHER_CONNECTION_BACKOFF_FACTOR
  @publisher_max_retries = DEFAULT_PUBLISHER_MAX_RETRIES
  @publisher_retry_base_delay = DEFAULT_PUBLISHER_RETRY_BASE_DELAY
  @publisher_retry_backoff_factor = DEFAULT_PUBLISHER_RETRY_BACKOFF_FACTOR
  @publisher_confirms_pool_size = DEFAULT_PUBLISHER_CONFIRMS_POOL_SIZE
  @publisher_confirms_timeout = DEFAULT_PUBLISHER_CONFIRMS_TIMEOUT
  @publisher_confirms_cleanup_timeout =
    DEFAULT_PUBLISHER_CONFIRMS_CLEANUP_TIMEOUT
  @logger = Logger.new(IO::NULL)
end

Instance Attribute Details

#connection_nameString

Returns the name for the RabbitMQ connection.

Returns:

  • (String)

    the name for the RabbitMQ connection.



28
29
30
# File 'lib/ears/configuration.rb', line 28

def connection_name
  @connection_name
end

#loggerLogger

Returns the logger instance for Ears operations.

Returns:

  • (Logger)

    the logger instance for Ears operations



61
62
63
# File 'lib/ears/configuration.rb', line 61

def logger
  @logger
end

#publisher_confirms_cleanup_timeoutFloat

Returns the timeout in seconds for cleanup operations after confirmation timeout.

Returns:

  • (Float)

    the timeout in seconds for cleanup operations after confirmation timeout



70
71
72
# File 'lib/ears/configuration.rb', line 70

def publisher_confirms_cleanup_timeout
  @publisher_confirms_cleanup_timeout
end

#publisher_confirms_pool_sizeInteger

Returns the size of the publisher confirms channel pool.

Returns:

  • (Integer)

    the size of the publisher confirms channel pool



64
65
66
# File 'lib/ears/configuration.rb', line 64

def publisher_confirms_pool_size
  @publisher_confirms_pool_size
end

#publisher_confirms_timeoutFloat

Returns the timeout in seconds for waiting for publisher confirms.

Returns:

  • (Float)

    the timeout in seconds for waiting for publisher confirms



67
68
69
# File 'lib/ears/configuration.rb', line 67

def publisher_confirms_timeout
  @publisher_confirms_timeout
end

#publisher_connection_attemptsInteger

Returns the number of connection attempts for the publisher.

Returns:

  • (Integer)

    the number of connection attempts for the publisher



43
44
45
# File 'lib/ears/configuration.rb', line 43

def publisher_connection_attempts
  @publisher_connection_attempts
end

#publisher_connection_backoff_factorFloat

Returns the backoff factor for exponential connection delays.

Returns:

  • (Float)

    the backoff factor for exponential connection delays



49
50
51
# File 'lib/ears/configuration.rb', line 49

def publisher_connection_backoff_factor
  @publisher_connection_backoff_factor
end

#publisher_connection_base_delayFloat

Returns the base delay in seconds between connection attempts.

Returns:

  • (Float)

    the base delay in seconds between connection attempts



46
47
48
# File 'lib/ears/configuration.rb', line 46

def publisher_connection_base_delay
  @publisher_connection_base_delay
end

#publisher_max_retriesInteger

Returns the maximum number of retries for failed publish attempts.

Returns:

  • (Integer)

    the maximum number of retries for failed publish attempts



52
53
54
# File 'lib/ears/configuration.rb', line 52

def publisher_max_retries
  @publisher_max_retries
end

#publisher_pool_sizeInteger

Returns the size of the publisher channel pool.

Returns:

  • (Integer)

    the size of the publisher channel pool



37
38
39
# File 'lib/ears/configuration.rb', line 37

def publisher_pool_size
  @publisher_pool_size
end

#publisher_pool_timeoutInteger

Returns the timeout in seconds for acquiring a channel from the publisher pool.

Returns:

  • (Integer)

    the timeout in seconds for acquiring a channel from the publisher pool



40
41
42
# File 'lib/ears/configuration.rb', line 40

def publisher_pool_timeout
  @publisher_pool_timeout
end

#publisher_retry_backoff_factorFloat

Returns the backoff factor for exponential retry delays.

Returns:

  • (Float)

    the backoff factor for exponential retry delays



58
59
60
# File 'lib/ears/configuration.rb', line 58

def publisher_retry_backoff_factor
  @publisher_retry_backoff_factor
end

#publisher_retry_base_delayFloat

Returns the base delay in seconds between retry attempts.

Returns:

  • (Float)

    the base delay in seconds between retry attempts



55
56
57
# File 'lib/ears/configuration.rb', line 55

def publisher_retry_base_delay
  @publisher_retry_base_delay
end

#rabbitmq_urlString

Returns the connection string for RabbitMQ.

Returns:

  • (String)

    the connection string for RabbitMQ.



25
26
27
# File 'lib/ears/configuration.rb', line 25

def rabbitmq_url
  @rabbitmq_url
end

#recover_from_connection_closeBoolean

Returns if the recover_from_connection_close value is set for the RabbitMQ connection.

Returns:

  • (Boolean)

    if the recover_from_connection_close value is set for the RabbitMQ connection.



31
32
33
# File 'lib/ears/configuration.rb', line 31

def recover_from_connection_close
  @recover_from_connection_close
end

#recovery_attemptsInteger

Returns max number of recovery attempts, nil means forever.

Returns:

  • (Integer)

    max number of recovery attempts, nil means forever



34
35
36
# File 'lib/ears/configuration.rb', line 34

def recovery_attempts
  @recovery_attempts
end

Instance Method Details

#recovery_attempts_exhaustedProc

Returns that is passed to Bunny’s recovery_attempts_exhausted block. Nil if recovery_attempts is nil.

Returns:

  • (Proc)

    that is passed to Bunny’s recovery_attempts_exhausted block. Nil if recovery_attempts is nil.



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ears/configuration.rb', line 92

def recovery_attempts_exhausted
  return nil unless recovery_attempts

  Proc.new do
    # We need to have this since Bunny’s multi-threading is cumbersome here.
    # Session reconnection seems not to be done in the main thread. If we want to
    # achieve a restart of the app we need to modify the thread behaviour.
    Thread.current.abort_on_exception = true
    raise MaxRecoveryAttemptsExhaustedError
  end
end

#validate!Object



104
105
106
# File 'lib/ears/configuration.rb', line 104

def validate!
  raise ConnectionNameMissing unless connection_name
end