Guest User

Untitled

a guest
Jan 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'amqp'
  2. AMQP.start(host: 'localhost', port: 5672) do |connection|
  3. channel = AMQP::Channel.new(connection)
  4. exchange = channel.topic("events")
  5.  
  6. # the first subscriber will declare a different queue name than the second
  7. # but will use the same routing key
  8. channel.queue("service1.usermanager.user.login").bind(exchange, :routing_key => "usermanager.user.login").subscribe do |metadata, payload|
  9. puts "Subscriber 1: An update for Service 1: #{payload}, routing key is #{metadata.routing_key}"
  10. end
  11.  
  12. show_stopper = Proc.new { puts 'closing the rabbit hole'; connection.close { EventMachine.stop } }
  13.  
  14. ['TERM'].each do |sig|
  15. Signal.trap sig, show_stopper
  16. end
  17. end
Add Comment
Please, Sign In to add comment