Automatically reconnect RabbitMQ channels

java, rabbitmq

Solution

Perhaps this is a new feature of the RabbitMQ client, but I found this in their docs:

To enable automatic connection recovery, use factory.setAutomaticRecoveryEnabled(true):

https://www.rabbitmq.com/api-guide.html

Looks like it should solve the problem.

Problem

I found this gem: In the event of a connection failure, the client will need to establish a new connection to the broker. Any channels opened on the previous connection will have been automatically closed and these will need re-opening too. So that's not good. I'm about to go write a big layer of handling automatic reconnects and recreating the channels then encapsulate this happening from all of my code. Problem is, this should be done already. Is this possible in the Java RMQ libraries?

Original source