Class: Tackle::Connection
- Inherits:
-
Object
- Object
- Tackle::Connection
- Defined in:
- lib/tackle/connection.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize(amqp_url, exception_handler, logger) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(amqp_url, exception_handler, logger) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 10 11 |
# File 'lib/tackle/connection.rb', line 5 def initialize(amqp_url, exception_handler, logger) @amqp_url = amqp_url @exception_handler = exception_handler @logger = logger connect end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
3 4 5 |
# File 'lib/tackle/connection.rb', line 3 def channel @channel end |
Instance Method Details
#close ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/tackle/connection.rb', line 32 def close @channel.close @logger.info("Closed channel") @connection.close @logger.info("Closed connection to RabbitMQ") end |
#connect ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tackle/connection.rb', line 13 def connect @logger.info("Connecting to RabbitMQ") @connection = Bunny.new(@amqp_url) @connection.start @logger.info("Connected to RabbitMQ") @channel = @connection.create_channel @channel.prefetch(1) @channel.on_uncaught_exception(&@exception_handler) @logger.info("Connected to channel") rescue StandardError => ex @logger.error("Error while connecting to RabbitMQ message='#{ex}'") raise ex end |