Class: RabbitHutch::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel, config, consumers) ⇒ Worker

Returns a new instance of Worker.



11
12
13
14
15
16
17
# File 'lib/worker.rb', line 11

def initialize(channel, config, consumers)
  @channel = channel
  @channel.on_error(&method(:handle_channel_exception))
  @consumer = Consumer.new(consumers)
  @exchange_name = config.application['exchangename']
  @queue_name = config.application['queuename']
end

Instance Method Details

#handle_channel_exception(channel, channel_close) ⇒ Object



27
28
29
# File 'lib/worker.rb', line 27

def handle_channel_exception(channel, channel_close)
  puts "Oops... a channel-level exception: code = #{channel_close.reply_code}, message = #{channel_close.reply_text}"
end

#startObject

begin listening for all topics in publish.#



20
21
22
23
24
25
# File 'lib/worker.rb', line 20

def start
  @exchange = @channel.topic(@exchange_name, :durable => true, :auto_delete => false, :internal => true)
  @queue = @channel.queue(@queue_name, :durable => true, :auto_delete => false)
  @queue.bind(@exchange, :routing_key => 'publish.#')
  @queue.subscribe(&@consumer.method(:handle_message))
end