Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View automatic_recovery_of_queues_bindings_and_consumers_example.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
require "rubygems"
require "amqp" # requires version >= 0.8.0.RC14
 
puts "=> Example of automatic AMQP channel and queues recovery"
puts
AMQP.start(:host => "localhost") do |connection, open_ok|
connection.on_error do |ch, connection_close|
raise connection_close.reply_text
end
 
ch1 = AMQP::Channel.new(connection)
ch1.auto_recovery = true
ch1.on_error do |ch, channel_close|
raise channel_close.reply_text
end
 
if ch1.auto_recovering?
puts "Channel #{ch1.id} IS auto-recovering"
end
 
connection.on_tcp_connection_loss do |conn, settings|
puts "[network failure] Trying to reconnect..."
conn.reconnect(false, 2)
end
 
 
ch1.queue("amqpgem.examples.queue1", :auto_delete => true).bind("amq.fanout")
ch1.queue("amqpgem.examples.queue2", :auto_delete => true).bind("amq.fanout")
ch1.queue("amqpgem.examples.queue3", :auto_delete => true).bind("amq.fanout").subscribe do |metadata, payload|
end
 
 
show_stopper = Proc.new {
connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
}
 
Signal.trap "TERM", show_stopper
Signal.trap "INT", show_stopper
EM.add_timer(30, show_stopper)
 
 
puts "Connected, authenticated. To really exercise this example, shut AMQP broker down for a few seconds. If you don't it will exit gracefully in 30 seconds."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.