Skip to content

Instantly share code, notes, and snippets.

@trinary
Created June 10, 2011 22:16
Show Gist options
  • Save trinary/1019900 to your computer and use it in GitHub Desktop.
Save trinary/1019900 to your computer and use it in GitHub Desktop.
#!/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