Reputation: 18511
after using a channel for a while, my rabbitmq restarts.
Then when the java client application (still running) tries to use the channel -
I get a trying to use a close channel.
Is there a way to check if the channel is closed ?
Is there a way to keep it open ?
IS there a way to do it without keeping it forever ?
(I want that when the server restarts it does delete the channel and queue but will be able to create them upon new usage)
Thanks.
Upvotes: 0
Views: 2276
Reputation: 132852
Channel
has an isOpen
method you can use.
What you want to do is monitor your connection so that when it's closed you want to start polling for the server to come back up again. Look at the documentation for Connection.addShutdownListener
and the ShutdownNotifier
interface.
Unfortunately, closed channels cannot be reconnected, you need to create new channels once the connection is back up again.
Upvotes: 1
Reputation: 272207
You may want to check out the Spring AMQP integration, and in particular Spring Retry. From section 2.12:
Spring Retry provides a couple of AOP interceptors and a great deal of flexibility to specify the parameters of the retry (number of attempts, exception types, backoff algorithm etc.). Spring AMQP also provides some convenience factory beans for creating Spring Retry interceptors in a convenient form for AMQP use cases, with strongly typed callback interfaces for you to implement custom recovery logic. See the Javadocs and properties of StatefulRetryOperationsInterceptor and StatelessRetryOperationsInterceptor for more detail.
Upvotes: 0