Question

using java client QueueingConsumer I wrote the following code to assist consumer recovery

while (true) {
   try{
      .. create connection
      .. create channel & queue
      while (true) {
             final QueueingConsumer.Delivery delivery = consumer.nextDelivery();
             ....
      } catch {
          handleException()
      }
}

And every time I restarted rabbit it survived cause it created the connection from start.
Now, I understand I should be working with DefaultConsumer.
So I have this method

public void handleDelivery(...) throws IOException {
}

and my problems are :

  1. I cant catch the exception inside and recreate the connection
  2. This only recovers when the ack fails. What if it fails in another stage of the process? How should I recover these fails?
    Thanks.
Was it helpful?

Solution

You should update to version 3.3.0 of the Rabbit Java Client. Finally, they have added support for reconnection and re-declaration of your topology.

You just need to set this when setting up the ConnectionFactory:

...
connectionFactory.setAutomaticRecoveryEnabled(true);
connectionFactory.setTopologyRecoveryEnabled(true);
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top