pythonrabbitmqpika

How to disable heartbeats with pika and rabbitmq


I am using rabbitmq to facilitate some tasks from my rabbit server to my respective consumers. I have noticed that when I run some rather lengthy tests, 20+ minutes, my consumer will lose contact with the producer after it completes it's task. In my rabbit logs, I have seen the error

closing AMQP connection <0.14009.27> (192.168.101.2:64855 -> 
192.168.101.3:5672):
missed heartbeats from client, timeout: 60s

Also, I receive this error from pika

pika.exceptions.ConnectionClosed: (-1, "error(10054, 'An existing connection was forcibly closed by the remote host')")

I'm assuming this is due to this code right here and the conflict of heartbeats with the lengthy blocking connection time.

 self.connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.101.2', 5672, 'user', credentials))
    self.channel = self.connection.channel()
    self.channel.queue_declare(queue=self.tool,
                               arguments={'x-message-ttl': 1000,
                                             "x-dead-letter-exchange": "dlx",
                                             "x-dead-letter-routing-key": "dl",
                                             'durable': True})

Is there a proper way to increase the heartbeat time or how would I turn it off(would it be wise to) completely? Like I said, tests that are 20+ min seem to lead to a closedconnection error but I've ran plenty of tests from the 1-15 minute mark where everything is fine and the consumer client continues to wait for a message to be delivered.


Solution

  • Please don't disable heartbeats. Instead, use Pika correctly. This means:

    Example code can be found here: link

    I'm a RabbitMQ core team member and Pika maintainer.