gpt4 book ai didi

python - Pika BlockingConnection 和 RabbitMQ : connection closed

转载 作者:行者123 更新时间:2023-12-02 07:30:16 25 4
gpt4 key购买 nike

我的集群中有 2 个rabbitmq,由 Azure 内部负载均衡器进行负载均衡。客户端通过 BlockingConnection 连接到负载均衡器。

当客户端交换消息时,一切正常。但是,当没有事件时,我的客户端似乎已断开连接,并且无法再接收消息。

我想知道这个问题有没有解决办法?我假设负载均衡器或rabbitmq 由于不活动而关闭连接。我想让pika向rabbitmq触发一些心跳(以便负载均衡器保持连接打开)但没有找到任何好的解决方案。你能给点建议吗?

编辑 1看来 pika BlockingConnections 不支持心跳。 Heart beat disables blocking connection

谢谢。

最佳答案

根据 Pika 文档 http://pika.readthedocs.org/en/0.10.0/modules/parameters.html ,看来 Pika 阻止了与 URLParameters 的联系指定heart_interval(如amqps://www-data:rabbit_pwd@rabbit1/web_messages?heartbeat_interval=30)可以保持连接打开,但heart_interval的值不能大于rabbit服务器建议的值。

Heartbeat Timeout Interval

The heartbeat timeout value defines after what period of time the peer TCP connection should be considered dead by RabbitMQ and client libraries. This value is negotiated between the client and RabbitMQ server at the time of connection. The client must be configured to request heartbeats. In RabbitMQ versions 3.0 and higher, the broker will attempt to negotiate heartbeats by default (although the client can still veto them). The timeout is in seconds, and default value is 60 (580 prior to release 3.5.5).

Heartbeat frames are sent about every timeout / 2 seconds. After two missed heartbeats, the peer is considered to be unreachable. Different clients manifest this differently but the TCP connection will be closed. When a client detects that RabbitMQ node is unreachable due to a heartbeat, it needs to re-connect.

Heartbeats can be disabled by setting the timeout interval to 0.

来自 Pika 文档的示例代码:

import pika

parameters = pika.URLParameters('amqps://www-data:rabbit_pwd@rabbit1/web_messages?heartbeat_interval=30')
connection = pika.BlockingConnection(parameters)

关于python - Pika BlockingConnection 和 RabbitMQ : connection closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34721178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com