Class: MessageQueue::Adapters::Bunny::Connection

Inherits:
Connection
  • Object
show all
Defined in:
lib/message_queue/adapters/bunny/connection.rb

Defined Under Namespace

Classes: Consumer, Producer

Instance Attribute Summary collapse

Attributes inherited from Connection

#serializer, #settings

Instance Method Summary collapse

Methods inherited from Connection

#initialize, #with_connection

Methods included from Logging

#logger, logger, logger=, setup_logger

Constructor Details

This class inherits a constructor from MessageQueue::Connection

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



2
3
4
# File 'lib/message_queue/adapters/bunny/connection.rb', line 2

def connection
  @connection
end

Instance Method Details

#connectObject

Public: Connect to RabbitMQ

Returns the Bunny instance



7
8
9
10
11
12
13
14
# File 'lib/message_queue/adapters/bunny/connection.rb', line 7

def connect
  @connection ||= begin
                    super
                    bunny = ::Bunny.new(bunny_settings)
                    bunny.start
                    bunny
                  end
end

#connected?Boolean

Public: Check if it’s connected to the message queue

Returns true if it’s connected

Returns:

  • (Boolean)


30
31
32
# File 'lib/message_queue/adapters/bunny/connection.rb', line 30

def connected?
  @connection.open? if @connection
end

#disconnectObject

Public: Disconnect from RabbitMQ

Returns nothing



19
20
21
22
23
24
25
# File 'lib/message_queue/adapters/bunny/connection.rb', line 19

def disconnect
  if @connection
    super
    @connection.close if @connection.open?
    @connection = nil
  end
end

#new_consumer(options) ⇒ Object



40
41
42
43
44
# File 'lib/message_queue/adapters/bunny/connection.rb', line 40

def new_consumer(options)
  raise "No connection to RabbitMQ" unless connection

  Consumer.new(self, options)
end

#new_producer(options) ⇒ Object



34
35
36
37
38
# File 'lib/message_queue/adapters/bunny/connection.rb', line 34

def new_producer(options)
  raise "No connection to RabbitMQ" unless connection

  Producer.new(self, options)
end