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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  @rabbitmq_url = DEFAULT_RABBITMQ_URL
  @recovery_attempts = DEFAULT_RECOVERY_ATTEMPTS
end

Instance Attribute Details

#connection_nameString

Returns the name for the RabbitMQ connection.

Returns:

  • (String)

    the name for the RabbitMQ connection.



16
17
18
# File 'lib/ears/configuration.rb', line 16

def connection_name
  @connection_name
end

#rabbitmq_urlString

Returns the connection string for RabbitMQ.

Returns:

  • (String)

    the connection string for RabbitMQ.



13
14
15
# File 'lib/ears/configuration.rb', line 13

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.



19
20
21
# File 'lib/ears/configuration.rb', line 19

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



22
23
24
# File 'lib/ears/configuration.rb', line 22

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.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ears/configuration.rb', line 30

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



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

def validate!
  raise ConnectionNameMissing unless connection_name
end