Created
November 22, 2011 22:06
-
-
Save dagda1/1387174 to your computer and use it in GitHub Desktop.
consumer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "start_consumer", "start the test consumer" | |
def start_consumer | |
puts "Running #{AMQP::VERSION} version of the gem" | |
AMQP.start(:host => "localhost", :user => "guest", :password => "guest", :vhost => "/", | |
:logging => true, :port => 5672) do |connection| | |
channel = AMQP::Channel.new(connection) | |
requests_queue = channel.queue("one", :exclusive => true, :auto_delete => true) | |
Signal.trap("INT") do | |
connection.close do | |
EM.stop{exit} | |
end | |
end | |
channel.prefetch(1) | |
requests_queue.subscribe(:ack => true) do |header, body| | |
puts "received in server #{body.inspect}" | |
(0..5).each do |n| | |
header.ack | |
reply = {:reply => "Respone #{n}", :is_last => (n == 5)} | |
AMQP::Exchange.default.publish( | |
MultiJson.encode(reply), | |
:routing_key => header.reply_to, | |
:correlation_id => header.correlation_id | |
) | |
sleep(2) | |
end | |
end | |
puts " [x] Awaiting RPC requests" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment