Skip to content Skip to sidebar Skip to footer

Pika Blockingconnection & Rabbitmq : Connection Closed

I have 2 rabbitmq in cluster load balanced by an Azure Internal Load Balancer. The client connect to the LB with BlockingConnection. When there a are message exchanged by the clie

Solution 1:

According to the Pika doc http://pika.readthedocs.org/en/0.10.0/modules/parameters.html, it seems Pika BlockingConnentions with URLParameters specified heart_interval(such as amqps://www-data:rabbit_pwd@rabbit1/web_messages?heartbeat_interval=30) that can keep connection opened, but the value of heart_interval can not larger than the value of rabbit server suggested.

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.

Sample code from Pika doc:

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

Post a Comment for "Pika Blockingconnection & Rabbitmq : Connection Closed"