BlockingConnection with heartbeat

1,234 views
Skip to first unread message

Mohammad Hossein Yazdani

unread,
Jul 22, 2022, 5:02:47 AM7/22/22
to Pika
Hello there

I wrote a web application with flask that in the application startup I try to create a connection pool of pika.BlockingConnection and share this connection pool in my app.

**********************
global connections
connections = [pika.BlockingConnection(pika.connection.URLParameters(connection_url))
for i in range(pool_size)]
**********************

I do not close the BlockingConnections at all. I just use one of these connections in connections list and return it back to the list again.

But my problem is after creating this connection pool after 20 sec(heartbeat=20) all of my connections will be closed by rabbitmq with log: missed heartbeats from client, timeout: 20s


it seems that pika.BlockingConnection does not send heartbeat frames at all.
What  is my mistake in this implementation?

Karl Sutt

unread,
Aug 3, 2022, 7:09:18 AM8/3/22
to Pika
Hey,

I recently ran into a similar issue and looking around on the internet it seems like there are quite a few people who are experiencing the same type of problems.

The main thing you will have to take into account is the fact that your connections have to respond to RabbitMQ heartbeats every once in a while. You should use the `Connection.process_data_events()` method and call it periodically to respond to heartbeats and other "data events".

I resolved the issue for my purposes and spotted a question about a similar issue on StackOverflow. Here's my response. I've also put together a Github repo with an example implementation on top of Docker and two RabbitMQ instances.

Luke Bakken

unread,
Aug 4, 2022, 9:00:40 AM8/4/22
to Pika
Thanks for responding!

I've been out on vacation and am catching up on RabbitMQ and Pika related issues.

Mohammad Hossein Yazdani

unread,
Aug 5, 2022, 12:29:10 PM8/5/22
to Pika
Thanks a lot for your response.
Is there any open issue on this problem in pika's github repo?
If there is , would you please mention that here.
I would like to follow this issue more.

Luke Bakken

unread,
Aug 5, 2022, 12:58:06 PM8/5/22
to Pika
Hello,

No, there is no open issue at this time because this is not technically a bug in Pika.

You can follow the discussion here - https://github.com/pika/pika/discussions/1382

Thanks!

Reply all
Reply to author
Forward
0 new messages