Guest User

Untitled

a guest
Jul 23rd, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. require "rubygems"
  2. require "bunny"
  3. require "json"
  4.  
  5. # Returns a connection instance
  6. conn = Bunny.new ENV['CLOUDAMQP_URL']
  7. # The connection will be established when start is called
  8. conn.start
  9.  
  10. # create a channel in the TCP connection
  11. ch = conn.create_channel
  12.  
  13. # Declare a queue with a given name, examplequeue. In this example is a durable shared queue used.
  14. q = ch.queue("examplequeue", :durable => true)
  15.  
  16. # Bind a queue to an exchange
  17. x = ch.direct("example.exchange", :durable => true)
  18. q.bind(x, :routing_key => "process")
  19.  
  20. # Publish a message
  21. information_message = "{\"email\": \"example@mail.com\",\"name\": \"name\",\"size\": \"size\"}"
  22.  
  23. x.publish(information_message,
  24. :timestamp => Time.now.to_i,
  25. :routing_key => "process"
  26. )
  27.  
  28. sleep 1.0
  29. conn.close
Add Comment
Please, Sign In to add comment