作者:乐檬 | 来源:互联网 | 2023-10-11 19:23
我在Azure内部负载平衡器平衡的群集负载中有2个rabbitmq.客户端使用BlockingConnection连接到LB.当客户端交换消息时,一切正常.但是,当没有活动时,似乎
我在Azure内部负载平衡器平衡的群集负载中有2个rabbitmq.客户端使用BlockingConnection连接到LB.
当客户端交换消息时,一切正常.但是,当没有活动时,似乎我的客户端已断开连接,并且不再能够接收消息.
我想知道是否有解决此问题的方法?我假设负载平衡器或Rabbitmq由于不活动而正在关闭连接.我想让pika触发rabbitmq的心跳(以便负载均衡器保持连接打开),但是找不到任何好的解决方案.你能建议吗?
编辑1
似乎pika BlockingConnections不支持心跳. Heart beat disables blocking connection
谢谢.
解决方法:
根据Pika doc http://pika.readthedocs.org/en/0.10.0/modules/parameters.html,似乎具有URLParameters指定的heart_interval的Pika BlockingConnentions(例如amqps:// www-data:rabbit_pwd @ rabbit1 / web_messages?heartbeat_interval = 30)可以保持连接打开,但是heart_interval的值不能更大比Rabbit服务器建议的值高.
07002
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 doc的示例代码:
import pika
parameters = pika.URLParameters('amqps://www-data:rabbit_pwd@rabbit1/web_messages?heartbeat_interval=30')
cOnnection= pika.BlockingConnection(parameters)