[英]Rabbitmq server drops connection when client takes more than 60 seconds to acknowledge a message
I am currently using EventingBasicConsumer from RabbitMQClient.dll C# client, we spawn a different thread to handle each message that is delivered to the consumer. 我目前正在使用RabbitMQClient.dll C#客户端中的EventingBasicConsumer,我们产生了一个不同的线程来处理传递给使用者的每条消息。
We encountered a strange behavior, the RabbitMQ server closes connections at times with the error missed heartbeats from client, timeout: 60s
. 我们遇到了一个奇怪的行为,RabbitMQ服务器有时会关闭连接,而
missed heartbeats from client, timeout: 60s
错误的missed heartbeats from client, timeout: 60s
。 Few moments later the client reports an error saying Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541
. 片刻之后,客户端报告一个错误,提示
Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541
。 I also see this error client unexpectedly closed TCP connection
happening more frequently. 我还看到此错误
client unexpectedly closed TCP connection
频率更高。
In some situations the clients may take more than 60 seconds to process one job request and this error happens under such conditions. 在某些情况下,客户可能需要60秒钟以上的时间来处理一个作业请求,并且在这种情况下会发生此错误。
Is it required that a job be processed within 60 seconds ?, because for our process this can vary between 30 seconds to 5 minutes. 是否需要在60秒内处理作业?因为对于我们的处理,这可能在30秒到5分钟之间变化。
RabbitMQ server: 3.6.6 RabbitMQ.Client.dll (C# client): RabbitMQ.Client.4.1.1 RabbitMQ服务器:3.6.6 RabbitMQ.Client.dll(C#客户端):RabbitMQ.Client.4.1.1
Any insight into this issue is greatly appreciated. 非常感谢您对此问题的见解。
I used to run much longer jobs (minutes) with EasyNetQ . 我曾经使用EasyNetQ运行更长的工作(几分钟)。 It's more high-level client that wraps
RabbitMQ.Client
. 包装
RabbitMQ.Client
的是更高级的客户端。
For me, the reason of these errors is something like Evk wrote in this comment . 对我来说,这些错误的原因类似于Evk在此评论中写道。 I would try EasyNetQ as it likely has fetching of messages decoupled from the handling process.
我会尝试EasyNetQ,因为它可能已获取与处理过程分离的消息。
You can increase the TTL timeout in RabbitMq both per queue and per message 您可以为每个队列和每个消息增加RabbitMq中的TTL超时
IBasicProperties mqProps = model.CreateBasicProperties();
mqProps.ContentType = "text/plain";
mqProps.DeliveryMode = 2;
mqProps.Expiration = "300000"
model.BasicPublish(exchangeName,
routingKey, mqProps,
messageBodyBytes);
Documentaion is at https://www.rabbitmq.com/ttl.html 文档位于https://www.rabbitmq.com/ttl.html
But I think you're better off by rewriting it to Async pattern for the actual processing of the message. 但是我认为最好将其重写为异步模式以进行消息的实际处理。
This might give you inspiration for doing async message processing with RabbitMq 这可能会给您启发,使用RabbitMq进行异步消息处理
https://codereview.stackexchange.com/questions/42836/listen-to-multiple-rabbitmq-queue-by-task-and-process-the-message https://codereview.stackexchange.com/questions/42836/listen-to-multiple-rabbitmq-queue-by-task-and-process-the-message
And in this question there are quite allot of information too on async message consumption. 在这个问题上,异步消息的使用也分配了很多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.