Class: Nezu::Runtime::Worker

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

Instance Method Summary collapse

Constructor Details

#initialize(channel, consumer = Consumer.new) ⇒ Worker

Returns a new instance of Worker.



4
5
6
7
8
9
10
# File 'lib/nezu/runtime/worker.rb', line 4

def initialize(channel, consumer = Consumer.new)
  @queue_name = consumer.class.queue_name
  Nezu.logger.info("queue name: #{@queue_name}")
  @channel = channel
  @channel.on_error(&method(:handle_channel_exception))
  @consumer = consumer
end

Instance Method Details

#handle_channel_exception(channel, channel_close) ⇒ Object



18
19
20
# File 'lib/nezu/runtime/worker.rb', line 18

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

#startObject



12
13
14
15
16
# File 'lib/nezu/runtime/worker.rb', line 12

def start
  Nezu.logger.info("[Nezu Worker] #{@queue_name}")
  @queue = @channel.queue(@queue_name, :exclusive => false)
  @queue.subscribe(&@consumer.method(:handle_message))
end