public
Created

Example 3 for "Messaging for Rubyists"

  • Download Gist
example3.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
require 'bunny'
 
# connecting to a broker
b = Bunny.new({}, {:spec => "09"})
b.start
 
# setup
e = b.exchange("exchange-03")
q = b.queue("queue-03")
q.bind e
 
# producer
e.publish("Message 1")
e.publish("Message 2")
 
# consumer 1
consumer_q1 = b.queue("queue-03")
msg = consumer_q1.pop
puts "This is the message: #{msg}"
puts "This is the payload: #{msg[:payload]}"
 
# consumer 2
consumer_q2 = b.queue("queue-03")
msg = consumer_q2.pop
puts "This is the message: #{msg}"
puts "This is the payload: #{msg[:payload]}"
 
b.stop

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.