Created
February 13, 2012 00:37
-
-
Save vsavkin/1812209 to your computer and use it in GitHub Desktop.
Example 3 for "Messaging for Rubyists"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment