Skip to content

Instantly share code, notes, and snippets.

@reqshark
Created June 10, 2012 17:26
Show Gist options
  • Select an option

  • Save reqshark/2906693 to your computer and use it in GitHub Desktop.

Select an option

Save reqshark/2906693 to your computer and use it in GitHub Desktop.
RabbitMQ-consumer
if defined?(Bundler); Bundler.setup; else; require "rubygems"; end
require "amqp"
EventMachine.run do
AMQP.connect(:host => "localhost", :username => "guest", :password => "guest") do |connection|
puts "Connected. Waiting for messages... Hit Control + C to stop me."
channel = AMQP::Channel.new(connection)
exchange = channel.direct("hello-exchange", :durable => true, :auto_delete => false)
channel.queue("hello-queue", :durable => true, :auto_delete => false).bind(exchange, :routing_key => "hola").subscribe do |header, body|
puts "Received #{body}"
connection.close { EventMachine.stop }
end
# stop on Control + c or after 1 second
stop = Proc.new { connection.close { EventMachine.stop } }
Signal.trap("INT", &stop)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment