Last active
December 10, 2015 22:18
-
-
Save celldee/4500579 to your computer and use it in GitHub Desktop.
Bunny 0.9.0 consumer and publisher to test publisher confirms
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
Publisher | |
--------- | |
require 'bunny' | |
conn = Bunny.new | |
conn.start | |
ch = conn.channel | |
ch.confirm_select | |
x = ch.direct('hello-exchange', :durable => true) | |
msg = ARGV[0] | |
100.times do |i| | |
x.publish("#{i}: #{msg}", :routing_key => 'hola') | |
end | |
ch.wait_for_confirms | |
#sleep 10 | |
conn.close # Without this close method there is a risk of lost messages as at 0.9.0.pre5 | |
-------- | |
Consumer | |
-------- | |
require 'bunny' | |
class HelloConsumer < Bunny::Consumer | |
end | |
conn = Bunny.new | |
conn.start | |
ch = conn.channel | |
x = ch.direct('hello-exchange', :durable => true) | |
q = ch.queue('hello-queue', :durable => true) | |
q.bind(x, :routing_key => 'hola') | |
consumer = HelloConsumer.new(ch, q, 'hello-consumer') | |
consumer.on_delivery do |delivery_info, properties, payload| | |
if payload == 'quit' | |
ch.work_pool.shutdown | |
else | |
puts payload | |
end | |
end | |
q.subscribe_with(consumer, :block => true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment