Created
October 30, 2012 01:54
-
-
Save kenmazaika/3977858 to your computer and use it in GitHub Desktop.
x-ha-policy header queue connection for bunny and amqp gems
This file contains hidden or 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 'rubygems' | |
| require 'amqp' | |
| def process(exchange_name, queue_name, configuration, key) | |
| AMQP.start(configuration) do |connection| | |
| channel = AMQP::Channel.new(connection) | |
| exchange = channel.fanout("amq.fanout") | |
| queue = channel.queue(queue_name, | |
| :durable => true, | |
| :arguments => { "x-ha-policy" => "all" }).bind(exchange) | |
| queue.subscribe(:ack => true) do |metadata, payload| | |
| puts "#{payload.inspect}" | |
| metadata.ack | |
| EventMachine.stop { exit } | |
| end | |
| end | |
| end |
This file contains hidden or 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 'rubygems' | |
| require 'bunny' | |
| def process(exchange_name, queue_name, configuration, key) | |
| bunny = Bunny.new(configuration) | |
| bunny.start | |
| queue = bunny.queue(queue_name, :durable => true, :arguments => {"x-ha-policy" => 'all'}) | |
| exchange = bunny.exchange(exchange_name, :type => :topic, :durable => true) | |
| queue.bind(exchange, :key => key) | |
| queue.subscribe(:timeout => 10) do |msg| | |
| puts msg.inspect | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment