Class: MessageQueue::Connection
- Inherits:
-
Object
- Object
- MessageQueue::Connection
- Includes:
- Logging
- Defined in:
- lib/message_queue/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#connect ⇒ Object
Public: Connect to the message queue.
-
#connected? ⇒ Boolean
Public: Check if it’s connected to the message queue.
-
#disconnect ⇒ Object
Public: Disconnect from the message queue.
-
#initialize(serializer, settings) ⇒ Connection
constructor
Public: Initialize a new Bunny connection.
- #new_consumer(options = {}) ⇒ Object
- #new_producer(options = {}) ⇒ Object
-
#with_connection(&block) ⇒ Object
Public: Connect to the message, execute the block and disconnect.
Methods included from Logging
#logger, logger, logger=, setup_logger
Constructor Details
#initialize(serializer, settings) ⇒ Connection
Public: Initialize a new Bunny connection.
serializer - The Serializer for dumping and loading payload.
settings - The Hash settings used to connect.
Returns a Connection wrapper for Bunny.
16 17 18 19 |
# File 'lib/message_queue/connection.rb', line 16 def initialize(serializer, settings) @serializer = serializer @settings = settings end |
Instance Attribute Details
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
6 7 8 |
# File 'lib/message_queue/connection.rb', line 6 def serializer @serializer end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
6 7 8 |
# File 'lib/message_queue/connection.rb', line 6 def settings @settings end |
Instance Method Details
#connect ⇒ Object
Public: Connect to the message queue
Returns nothing
24 25 26 |
# File 'lib/message_queue/connection.rb', line 24 def connect logger.info("Connecting to message queue with adapter #{self.class} and settings #{settings}") end |
#connected? ⇒ Boolean
Public: Check if it’s connected to the message queue
Returns true if it’s connected
38 39 40 |
# File 'lib/message_queue/connection.rb', line 38 def connected? false end |
#disconnect ⇒ Object
Public: Disconnect from the message queue
Returns nothing
31 32 33 |
# File 'lib/message_queue/connection.rb', line 31 def disconnect logger.info("Disconnecting from message queue") end |
#new_consumer(options = {}) ⇒ Object
58 59 60 |
# File 'lib/message_queue/connection.rb', line 58 def new_consumer( = {}) Consumer.new(self, ) end |
#new_producer(options = {}) ⇒ Object
54 55 56 |
# File 'lib/message_queue/connection.rb', line 54 def new_producer( = {}) Producer.new(self, ) end |
#with_connection(&block) ⇒ Object
Public: Connect to the message, execute the block and disconnect
Returns nothing
45 46 47 48 49 50 51 52 |
# File 'lib/message_queue/connection.rb', line 45 def with_connection(&block) begin connect block.call(self) ensure disconnect end end |