[rabbitmq-discuss] dealing with a closing connection
Matthias Radestock
matthias at lshift.net
Wed Feb 6 06:28:52 GMT 2008
Steve,
Steve Jenson wrote:
> How can I use the rabbitmq java library to determine that the
> Connection has been closed so I can reestablish?
You could call isOpen() on the connection/channel, either periodically
or before attempting an operation, to check whether the connection is
still open, and attempt reconnection if not. This does of course leave a
time window where an operation may be attempted when the connection is
closed, which may or may not be a problem for your application.
In the .net client you can install event handlers on connection/channel
objects that get notified of shutdowns, which is neater but still
suffers from the same problem.
The better approach is to catch the IOException resulting from any
operation the client attempts, check that the cause is a
ShutdownSignalException, and then perform the necessary reconnection
actions.
Matthias.
More information about the rabbitmq-discuss
mailing list