rabbitmq-tutorials/ruby-amqp/worker.rb
Michael Klishin 2ec87888cb ruby => ruby-amqp
ruby should be done with Bunny 0.9 which is much easier to use
for beginners.
2013-07-17 18:07:03 +04:00

27 lines
549 B
Ruby
Executable File

#!/usr/bin/env ruby
# encoding: utf-8
require "amqp"
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
queue = channel.queue("task_queue", :durable => true)
Signal.trap("INT") do
connection.close do
EM.stop { exit }
end
end
puts " [*] Waiting for messages. To exit press CTRL+C"
channel.prefetch(1)
queue.subscribe(:ack => true) do |header, body|
puts " [x] Received #{body}"
EM.add_timer(body.count(".")) do
puts " [x] Done"
header.ack
end
end
end