[rabbitmq-discuss] dealing with a closing connection

Steve Jenson stevej at gmail.com
Wed Feb 6 17:37:37 GMT 2008


On Feb 5, 2008 10:28 PM, Matthias Radestock <matthias at lshift.net> wrote:
> 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.

Connection and Channel have no method for determining whether they are
still open that I can tell, unfortunately.

> 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.

I'm using basicConsume and see no exceptions when the connection is
closed, my consumer is simply never called again.

I certainly don't mind handling an exception or checking if the
connection is open, I just don't see a way to do either.

Steve




More information about the rabbitmq-discuss mailing list