Class: MessageQueue::Connection

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/message_queue/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#serializerObject (readonly)

Returns the value of attribute serializer.



6
7
8
# File 'lib/message_queue/connection.rb', line 6

def serializer
  @serializer
end

#settingsObject (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

#connectObject

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

#disconnectObject

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(options = {})
  Consumer.new(self, options)
end

#new_producer(options = {}) ⇒ Object



54
55
56
# File 'lib/message_queue/connection.rb', line 54

def new_producer(options = {})
  Producer.new(self, options)
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