Class: JackRabbit::Subscription

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/jack_rabbit/subscription.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ blocking: false }

Constants included from Logging

Logging::TAG

Instance Method Summary collapse

Methods included from Logging

#set_logger

Constructor Details

#initialize(channel, exchange, key, queue, options, &block) ⇒ Subscription

Returns a new instance of Subscription.



10
11
12
13
14
# File 'lib/jack_rabbit/subscription.rb', line 10

def initialize(channel, exchange, key, queue, options, &block)
  @channel = channel
  @exchange, @key, @queue, @options = exchange, key, queue, options
  @block = block
end

Instance Method Details

#declareObject



16
17
18
19
20
21
22
23
24
# File 'lib/jack_rabbit/subscription.rb', line 16

def declare
  exchange = @channel.create_exchange(@exchange, @options)
  queue = @channel.create_queue(@queue, @options)
  queue.bind(exchange, { routing_key: @key })
  @subscription =
    queue.subscribe(DEFAULT_OPTIONS.merge(@options)) do |meta, message|
      @block.call(MessageHeader.new(meta), message)
    end
end