rabbitmq-tutorials/ruby/worker.rb
Michael Klishin 7782ad07b5 Make the code match the narrative
Spotted by the Mr. Eagle Eye, @videlalvaro.
2013-08-04 19:03:26 +04:00

26 lines
554 B
Ruby

#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"
conn = Bunny.new(:automatically_recover => false)
conn.start
ch = conn.create_channel
q = ch.queue("task_queue", :durable => true)
ch.prefetch(1)
puts " [*] Waiting for messages. To exit press CTRL+C"
begin
q.subscribe(:manual_ack => true, :block => true) do |delivery_info, properties, body|
puts " [x] Received '#{body}'"
# imitate some work
sleep body.count(".").to_i
puts " [x] Done"
ch.ack(delivery_info.delivery_tag)
end
rescue Interrupt => _
conn.close
end