2

I'm trying to recover the connection in RMQ for Clustered environment but unfortunately i'm not able to recover it in code and its also not catching in my exception.

For example. Initially node 1 is connected and our messages has been flow successfully and to test fail-over, we brought up node 2 and stopped node 1.. connections are being lost which is expected, but retry is not happening as node 2 is up.

When i restart my service, i'm able to get exception as:

"Rabbit MQ Message Exception : Error = 'connection is already closed due to
 connection error; cause: java.net.SocketException: Connection reset'"

Can anyone please suggest how to recover it in such case?

Have used below configurations in my code. (AMQP client):

 factory.setAutomaticRecoveryEnabled(true);
 factory.setNetworkRecoveryInterval(5000);
 factory.setTopologyRecoveryEnabled(true);
 factory.setRequestedHeartbeat(60);  

By using Lyra connection recovery will occur with following config:

 .withRetryPolicy(new RetryPolicy()
    .withMaxAttempts(30)
    .withInterval(Duration.seconds(1))
    .withMaxDuration(Duration.minutes(5))); 
Eldar Dordzhiev
  • 5,105
  • 2
  • 22
  • 26
Muthu
  • 71
  • 1
  • 3
  • Have you configured your client with node1 and node2 ? – Nicolas Labrot Apr 20 '16 at 13:52
  • Its load balance server and we have given DNS name on connecting to it.. so it will pick automatically – Muthu Apr 20 '16 at 14:38
  • Could you please copy/past the full connection configuration. Do `node1` and `node2` the name of the RabbitMQ cluster nodes? – Nicolas Labrot Apr 20 '16 at 14:58
  • I just want to retrieve the messages from RMQ, so i feel that, from my point of view, my code should connect to the node which is available that** Since i'm not able to catch any exception in my block, my recovery is not happening.not sure where the problem is factory = new ConnectionFactory(); factory.setHost(*******); factory.setPort(******); factory.setVirtualHost(*******); factory.setUsername(********); factory.setPassword(********); – Muthu Apr 21 '16 at 09:41
  • Have a look at [`org.springframework.amqp.rabbit.connection.CachingConnectionFactory`](http://docs.spring.io/spring-amqp/api/org/springframework/amqp/rabbit/connection/CachingConnectionFactory.html) and especially `setAddresses` which allows recovering on a different node. – Nicolas Labrot Apr 21 '16 at 09:51

0 Answers0