Class: MessageQueue::Adapters::Bunny::Connection
- Inherits:
-
Object
- Object
- MessageQueue::Adapters::Bunny::Connection
- Defined in:
- lib/message_queue/adapters/bunny/connection.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#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 RabbitMQ.
-
#disconnect ⇒ Object
Public: Disconnect from RabbitMQ.
-
#initialize(serializer, settings) ⇒ Connection
constructor
Public: Initialize a new Bunny connection.
- #new_consumer(options) ⇒ Object
- #new_publisher(options) ⇒ Object
-
#with_connection(&block) ⇒ Object
Public: Connect to RabbitMQ, execute the block and disconnect.
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 with Bunny.
Details in http://rubybunny.info/articles/connecting.html.
Returns a Connection wrapper for Bunny.
12 13 14 15 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 12 def initialize(serializer, settings) @serializer = serializer @settings = settings end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
2 3 4 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 2 def connection @connection end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
2 3 4 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 2 def serializer @serializer end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
2 3 4 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 2 def settings @settings end |
Instance Method Details
#connect ⇒ Object
Public: Connect to RabbitMQ
Returns the Bunny instance
20 21 22 23 24 25 26 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 20 def connect @connection ||= begin bunny = ::Bunny.new(settings) bunny.start bunny end end |
#disconnect ⇒ Object
Public: Disconnect from RabbitMQ
Returns nothing
31 32 33 34 35 36 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 31 def disconnect if @connection @connection.close if @connection.open? @connection = nil end end |
#new_consumer(options) ⇒ Object
56 57 58 59 60 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 56 def new_consumer() raise "No connection to RabbitMQ" unless connection Consumer.new(self, ) end |
#new_publisher(options) ⇒ Object
50 51 52 53 54 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 50 def new_publisher() raise "No connection to RabbitMQ" unless connection Publisher.new(self, ) end |
#with_connection(&block) ⇒ Object
Public: Connect to RabbitMQ, execute the block and disconnect
Returns nothing
41 42 43 44 45 46 47 48 |
# File 'lib/message_queue/adapters/bunny/connection.rb', line 41 def with_connection(&block) begin connect block.call(self) ensure disconnect end end |