Erlang Mailing Lists

Author Message

<  RabbitMQ mailing list  ~  dealing with a closing connection

Guest
Posted: Mon Feb 04, 2008 9:30 pm Reply with quote
Guest
Hi,

I'm using the Java client library to connect to a rabbitmq server
(1.2.0). Sometimes I will restart the server which obviously will
restart rabbitmq and my client application will print out a message to
the console.

AMQConnection.mainLoop: connection close

How can I use the rabbitmq java library to determine that the
Connection has been closed so I can reestablish? I could periodically
close() and recreate the Connection from the ConnectionFactory but I'm
hoping there's something nicer available that I have missed.

Thanks,
Steve

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Post recived from mailinglist
Guest
Posted: Wed Feb 06, 2008 6:29 am Reply with quote
Guest
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.

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Post recived from mailinglist
Guest
Posted: Wed Feb 06, 2008 5:38 pm Reply with quote
Guest
On Feb 5, 2008 10:28 PM, Matthias Radestock <matthias@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

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Post recived from mailinglist
Guest
Posted: Wed Feb 06, 2008 6:57 pm Reply with quote
Guest
Steve,

Steve Jenson wrote:

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

Ah yes, I forgot those methods aren't in the Connection/Channel
interfaces (as they are for the .Net client). You can find them in the
implementation classes AMQConnection and AMQChannel though.

This is an area we are planning to revise in a future release, probably
by following the example of the .Net client.

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

You should be able to override Consumer.handleShutdownSignal(String,
ShutdownSignalException), which ought to get called when the connection
or channel are shut down.


Matthias.

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Post recived from mailinglist
Guest
Posted: Wed Feb 06, 2008 7:23 pm Reply with quote
Guest
On Feb 6, 2008 10:56 AM, Matthias Radestock <matthias@lshift.net> wrote:
> Steve,
>
> Steve Jenson wrote:
>
> > Connection and Channel have no method for determining whether they are
> > still open that I can tell, unfortunately.
>
> Ah yes, I forgot those methods aren't in the Connection/Channel
> interfaces (as they are for the .Net client). You can find them in the
> implementation classes AMQConnection and AMQChannel though.
>
> This is an area we are planning to revise in a future release, probably
> by following the example of the .Net client.

I look forward to trying it out.

> > I'm using basicConsume and see no exceptions when the connection is
> > closed, my consumer is simply never called again.
>
> You should be able to override Consumer.handleShutdownSignal(String,
> ShutdownSignalException), which ought to get called when the connection
> or channel are shut down.

That's perfect, thank you. I will give that a try.

Steve

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum