Created
June 10, 2011 22:16
-
-
Save trinary/1019900 to your computer and use it in GitHub Desktop.
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
#!/bin/env ruby | |
#gem install eventmachine | |
#gem install amqp --pre | |
require 'rubygems' | |
require 'amqp' | |
require 'eventmachine' | |
max = ARGV[1] || 100 | |
queuename = ARGV[2] || "decoder_dispatch_queue" | |
host = ARGV[3] || "ops-db01" | |
count = 0 | |
EventMachine.run do | |
connection = AMQP.connect(:host => host) | |
puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..." | |
channel = AMQP::Channel.new(connection) | |
queue = channel.queue(queuename, :auto_delete => true) | |
exchange = channel.direct("") | |
queue.subscribe do |payload| | |
puts "Received a message: #{payload}" | |
count = count + 1 | |
if count > max | |
connection.close { EventMachine.stop { exit } } | |
end | |
end | |
puts "Subscribed." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment