Class: Lapine::Consumer::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/lapine/consumer/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, topic) ⇒ Connection

Returns a new instance of Connection.



9
10
11
12
13
# File 'lib/lapine/consumer/connection.rb', line 9

def initialize(config, topic)
  @connection = AMQP.connect(config.connection_properties)
  @channel = AMQP::Channel.new(connection)
  @exchange = AMQP::Exchange.new(channel, :topic, topic, durable: true)
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



7
8
9
# File 'lib/lapine/consumer/connection.rb', line 7

def channel
  @channel
end

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/lapine/consumer/connection.rb', line 7

def connection
  @connection
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



7
8
9
# File 'lib/lapine/consumer/connection.rb', line 7

def exchange
  @exchange
end

Instance Method Details

#close!Object



15
16
17
# File 'lib/lapine/consumer/connection.rb', line 15

def close!
  @connection.close if @connection.connected?
end