Guest User

Untitled

a guest
Sep 2nd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. require "amqp"
  2.  
  3. AMQP_CONFIG = {
  4. host: '127.0.0.1',
  5. port: 5671,
  6. username: '<...>',
  7. password: '<...>',
  8. ssl: true
  9. }
  10.  
  11. EventMachine.run do
  12. connection = AMQP.connect(AMQP_CONFIG)
  13. channel = AMQP::Channel.new(connection)
  14. channel.queue("org.haggett.amqptest", :exclusive => true, :auto_delete => true) do |queue, declare_ok|
  15. puts "Declared work queue."
  16.  
  17. queue.subscribe(:ack => true) do |metadata, payload|
  18. received_time = payload
  19. start_time = Time.now.to_f
  20.  
  21. EM.add_timer(rand(2.0)) do
  22. end_time = Time.now.to_f
  23.  
  24. channel.default_exchange.publish([received_time, start_time, end_time].join(":"), :routing_key => metadata.reply_to, :mandatory => true)
  25. metadata.ack
  26. end
  27.  
  28. end
  29. end
  30.  
  31. Signal.trap("INT") { connection.close { EventMachine.stop } }
  32. end
Add Comment
Please, Sign In to add comment