Class: Tackle::Consumer::MainQueue

Inherits:
Queue
  • Object
show all
Defined in:
lib/tackle/consumer/main_queue.rb

Instance Attribute Summary

Attributes inherited from Queue

#name

Instance Method Summary collapse

Methods inherited from Queue

#create_amqp_queue

Constructor Details

#initialize(exchange, connection, logger) ⇒ MainQueue

Returns a new instance of MainQueue.



5
6
7
8
9
10
11
12
13
14
# File 'lib/tackle/consumer/main_queue.rb', line 5

def initialize(exchange, connection, logger)
  @exchange = exchange

  name = @exchange.name
  options = { :durable => true }

  super(name, options, connection, logger)

  bind_to_exchange
end

Instance Method Details

#bind_to_exchangeObject



16
17
18
19
20
21
22
23
# File 'lib/tackle/consumer/main_queue.rb', line 16

def bind_to_exchange
  @logger.info("Binding queue '#{name}' to exchange '#{@exchange.name}' with routing_key '#{@exchange.routing_key}'")

  @amqp_queue.bind(@exchange, :routing_key => @exchange.routing_key)
rescue Exception => ex
  @logger.error "Failed to bind queue to exchange '#{ex}'"
  raise ex
end

#subscribe(&block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tackle/consumer/main_queue.rb', line 25

def subscribe(&block)
  options = { :manual_ack => true, :block => true }

  @amqp_queue.subscribe(options) do |delivery_info, properties, payload|
    message = Message.new(@connection,
                          @logger,
                          delivery_info,
                          properties,
                          payload)

    block.call(message)
  end
end