Skip to content

Instantly share code, notes, and snippets.

@pdlug
Created May 9, 2011 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdlug/962855 to your computer and use it in GitHub Desktop.
Save pdlug/962855 to your computer and use it in GitHub Desktop.
AMQP connection failure handling
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