Guest User

Untitled

a guest
Oct 19th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. if defined?(Bundler); Bundler.setup; else; require "rubygems"; end
  2.  
  3. require "amqp"
  4.  
  5. EventMachine.run do
  6. AMQP.connect(:host => "localhost", :username => "guest", :password => "guest") do |connection|
  7. puts "Connected. Waiting for messages... Hit Control + C to stop me."
  8.  
  9. channel = AMQP::Channel.new(connection)
  10. exchange = channel.direct("hello-exchange", :durable => true, :auto_delete => false)
  11. channel.queue("hello-queue", :durable => true, :auto_delete => false).bind(exchange, :routing_key => "hola").subscribe do |header, body|
  12. puts "Received #{body}"
  13.  
  14. connection.close { EventMachine.stop }
  15. end
  16.  
  17. # stop on Control + c or after 1 second
  18. stop = Proc.new { connection.close { EventMachine.stop } }
  19. Signal.trap("INT", &stop)
  20. end
  21. end
Add Comment
Please, Sign In to add comment