RabbitMQ Java client auto reconnect

后端 未结 1 786
不知归路
不知归路 2021-02-06 15:13

When my application looses connection to RabbitMQ I have its connection factory set to automatically try and reconnect

ConnectionFactory factory = new Connection         


        
相关标签:
1条回答
  • 2021-02-06 15:23

    To wrap it all together, here my answer.

    First of all rabbitmq, or at least the java client, has some weird default properties which are sometimes in seconds and sometimes in milliseconds. Also their default values do not seem well thought from my point of view. For example connectionTimeouts default value is 0, which means wait for ever.

    You should also set the networkRecoveryInterval property to some usefull value in your environment.

    To get a more information what caused the channel to close, implement a ShutdownListener - Even if it just prints the exception, it will help you to find out what caused the error.

    To test auto recovery of a connection I used an ip tables command on the client side. Then you can also see what happens on the server side in the rabbitmq.log

    And do not forget to adjust the requestHeartbeet property, in my setup its always above 5 seconds, the default one is in some client implementations 580 seconds which seems a bit strange also, keep that in mind.

    In any way, even if you run rabbitmq in a cluster, it does not work well on unreliable networks. Maybe you are interested in more regarding this than I should advise you to look in the documentation.

    0 讨论(0)
提交回复
热议问题