Created
May 9, 2011 16:45
-
-
Save pdlug/962855 to your computer and use it in GitHub Desktop.
AMQP connection failure handling
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
def setup_connection(connection) | |
# open channel, set up exchanges and bindings, subscribe | |
end | |
AMQP.start( | |
:host => '127.0.0.1', | |
:vhost => '/search', | |
:timeout => 0.3, | |
:on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect"; EM.stop }) do |connection, open_ok| | |
connection.on_connection do |cl| | |
setup_connection(cl) | |
end | |
connection.on_tcp_connection_loss do |cl, settings| | |
puts "reconnecting..." | |
cl.reconnect(false, 1) | |
cl.on_connection do |conn| | |
puts "on_connection called" | |
#setup_connection(conn) | |
end | |
end | |
trap(:INT) do | |
unless connection.closing? | |
connection.close { EM.stop { exit } } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment