Pika mix closed after three heartbeats

I am writing a script that receives HTTP requests (using Tornado), parses them, and sends them to the RabbitMQ broker using pika.

The code is as follows:

def main(): conn_params = pika.ConnectionParameters( host=BROKER_NAME, port=BROKER_PORT, ssl=True, virtual_host=VIRTUAL_HOST, credentials=pika.PlainCredentials(BROKER_USER, BROKER_PASS), heartbeat_interval=HEARTBEAT_INTERVAL ) conn = pika.BlockingConnection(conn_params) channel = conn.channel() # Create the web server which handles application requests. application = tornado.web.Application([ (URL_BILLING, SomeHandler, dict(channel=channel)) ]) # Start the server application.listen(LISTENING_PORT) tornado.ioloop.IOLoop.instance().start() 

As you can see, I open one connection and channel and pass the channel to any handler instance that is created, the idea is to save traffic and not open a new connection / channel for each request.

The problem I encountered is that the connection closes after 3 heart contractions . I used Wireshark to find out what the problem is, but all I see is that the server sends PSH (I assume it is a heartbeat) and my scripts respond with ACK. This happens 3 times with HEARTBEAT_INTERVAL between them, and then the server just sends FIN and the connection dies.

Any idea why this is happening? Also, should I keep the connection open or is it better to create a new one for each message I need to send?

Thanks for the help.

UPDATE: I looked into the RabbitMQ log and it says: Missed heartbeats from client, timeout: 10s I thought the server should send heartbeats to the client to make sure it is responding, and this is consistent with what I observed using Wireshark. but from this log it seems that the client should report to the server, and not vice versa, and the client obviously does not report. Do I understand this correctly?

UPDATE: It turned out something like. A blocking connection (this is what I used) cannot send heartbeats because it is, well, blocking. As mentioned in this problem , the heartbeat_interval parameters are used only to coordinate the connection with the server, but the client does not actually send heartbeats, so how is that the best way to keep a long connection with pika? Even if I do not specify heartbeat_interval , the default server will beat every 10 minutes, so the connection will die in 30 minutes ...

+6
source share
1 answer

For future visitors:

Pika has an asynchronous example that uses a heartbeat: http://pika.readthedocs.org/en/0.10.0/examples/asynchronous_publisher_example.html

For Tornado, this example shows how to use Tornado IOLoop in the pyn async model: http://pika.readthedocs.org/en/0.10.0/examples/tornado_consumer.html

+4
source

All Articles