Skip to content

Instantly share code, notes, and snippets.

@pdlug pdlug/gist:962855
Created May 9, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.