public
Created

Example 2 for "Messaging for Rubyists"

  • Download Gist
example2.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
require 'bunny'
 
# connecting to a broker
b = Bunny.new({}, {:spec => "09"})
b.start
 
# setup
e = b.exchange("exchange-02", :durable => true)
q = b.queue("queue-02")
q.bind e
 
# producer
e.publish("Message Body", :persistent => true)
 
# consumer
msg = q.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.