Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created October 30, 2012 01:54
Show Gist options
  • Select an option

  • Save kenmazaika/3977858 to your computer and use it in GitHub Desktop.

Select an option

Save kenmazaika/3977858 to your computer and use it in GitHub Desktop.
x-ha-policy header queue connection for bunny and amqp gems
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
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