Created
June 10, 2012 17:26
-
-
Save reqshark/2906693 to your computer and use it in GitHub Desktop.
RabbitMQ-consumer
This file contains hidden or 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
| 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