简体   繁体   English

兔子MQ重新启动后,使用者不重新连接

[英]Consumers do not reconnect after Rabbit MQ restart

Sometimes our rabbit messaging server requires a restart. 有时我们的Rabbit消息传递服务器需要重新启动。 After which however some consumers which are listening via basic consume blocking call do not consume any messages until they are restarted themselves and neither do they raise any exception. 但是,在此之后,一些通过基本的消费阻止呼叫进行监听的使用者不会消耗任何消息,除非他们自己重新启动,并且它们也不会引发任何异常。

What is the reason for this and how might I fix? 这是什么原因,我该如何解决?

In the connectionFactory, please ensure the following property is set to true: 在connectionFactory中,请确保将以下属性设置为true:

 factory.setAutomaticRecoveryEnabled(true); 

For more details, please refer the document here 有关更多详细信息,请在此处参考文档

As I mentioned in my comment, every AMQP client library has a different way to recover connections, and some depend on the developer to do that. 正如我在评论中提到的那样,每个AMQP客户端库都有不同的恢复连接的方法,有些依赖于开发人员来完成。 There is NO canonical method. 没有规范的方法。

Pika has this example as a starting point for connection recovery. Pika 将此示例作为连接恢复的起点 Note that the code is for the unreleased version of Pika ( 1.0.0 ). 请注意,该代码用于Pika的未发行版本( 1.0.0 )。 If you're on 0.12.0 you will have to adjust the parameters to the method calls. 如果您使用的是0.12.0 ,则必须将参数调整为方法调用。

The best way to test and implement connection recovery is to simulate failure conditions and then code for them. 测试和实现连接恢复的最佳方法是模拟故障条件,然后为它们编写代码。 Run your application, then kill the beam.smp process (RabbitMQ) to see what happens. 运行您的应用程序,然后beam.smp进程(RabbitMQ)以查看会发生什么。 If you have a RabbitMQ cluster, use firewall rules to simulate a network partition. 如果您有RabbitMQ集群,请使用防火墙规则来模拟网络分区。 Can your application handle that? 您的应用程序可以处理吗? What happens when you run rabbitmqctl stop_app; sleep 10; rabbitmqctl start_app 运行rabbitmqctl stop_app; sleep 10; rabbitmqctl start_app会发生什么? rabbitmqctl stop_app; sleep 10; rabbitmqctl start_app rabbitmqctl stop_app; sleep 10; rabbitmqctl start_app ? rabbitmqctl stop_app; sleep 10; rabbitmqctl start_app吗? Can your app handle that? 您的应用程序可以处理吗?

Run your application through a TCP proxy like toxiproxy and introduce latency and other non-optimal conditions. 通过诸如toxiproxy类的TCP代理运行您的应用程序,并引入延迟和其他非最佳条件。 Shut down the proxy to simulate a sudden TCP connection close. 关闭代理以模拟突然的TCP连接关闭。 In each case, code for that failure condition and log the event so that someone can later diagnose what has happened. 在每种情况下,都为该故障情况编写代码并记录事件,以便以后有人可以诊断出发生了什么。

I have seen too many developers code for the "happy path" only to have their applications fail spectacularly in production with zero ability to determine the source of the failure. 我已经看到太多的开发人员为“​​幸福的道路”编写代码,只是为了使他们的应用程序在生产中出现严重故障,而无法确定故障根源的能力为零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM