I am developing an RabbitMQ consumer with pika 0.10.0, and python 2.7 version.In my consumer client, I have a process that runs for a time period depending on input message. It can vary from 3 to 40 minutes. I do not want to disable heartbeat. Instead I am looking for some collback mechanism that can keep the connection alive until the delivery_tag is sent back. Is that possible?
Few link I got, all are suggesting to disable the heartbeat as workaround. But I do not want to disable it.
Ref:
Socket Error: 104 consuming messages with task that take a long time #753
BlockingConnection gets closed unexpectedly #734
Also, please let me know if any extra information is required. Thanks in advance.
Pika picks the highest heartbeat value between client and server (and this is the norm in AMQP clients). This means that if you set a heartbeat value lower than 60 seconds, Pika will always pick RabbitMQ's value because it's higher.
RabbitMQ heartbeats help the application layer detect interrupted connections and unresponsive peers in a timely manner. Heartbeats also prevent some network devices from disconnecting TCP connections where there is no activity for a certain period of time.
The solution is to close your connection in the close-callback of the channel. Also, use a context manager to automatically close the channel. params = pika. ConnectionParameters(host=self.
The only solution is to send heartbeat frames periodically.
When using a BlockingConnection
, you have to call the process_data_events
function frequently enough (a time_limit
of zero is ok). When using a SelectConnection
or other async adapters, you have to ensure none of your processes are blocking, so that frames can be sent.
If your task is long running and you can't interrupt or split the process easily for some reason, you can run the task in another thread/process, and still have pika sending frames from the main thread. Just keep in mind that you should avoid using pika connections across threads (pika is not thread-safe at the moment).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With