How to disable heartbeats with pika and rabbitmq

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



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.




2 Answers
2



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


0.12.0


add_callback_threadsafe


basic_ack



Example code can be found here: link



I'm a RabbitMQ core team member and Pika maintainer so if you have further questions or issues, I recommend following up on either the pika-python or rabbitmq-users mailing list. Thanks!


pika-python


rabbitmq-users



NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.


rabbitmq-users





This is actually the recommended way to go. Nevertheless IMHO this should be something provided by Pika. Pushing the users to go MT is not ideal. Especially considering now Pika has blocking connections.
– noxdafox
Aug 9 at 8:37





I've been maintaining Pika since version 0.11.0 and, as far as I know, Pika has always required that the user not block the ioloop, even when using the blocking connection. This is not Pika nor even Python-specific - you can't block the ioloop when using libuv, for instance, or your own select loop. What Pika now provides are more obvious methods to use when you need to schedule calls to be executed in the same thread as what the ioloop runs. I realize this isn't the most user-friendly scenario and will be improving docs and examples for version 1.0.0
– Luke Bakken
Aug 9 at 21:45


0.11.0


libuv


select


1.0.0



You can set the minimum heartbeat interval when creating the connection.


connection



You can see an example in the pika documentation.



I'd recommend against disabling the heartbeat as it might lead to hanging connections piling up on the broker. We experienced such issue in production.



Always make sure the connections have a minimum reasonable heartbeat. If the heartbeat interval needs to be long (hours for example), make sure you close the connection when the application crashes or exits. In this way you won't leave the connection open on the broker side.





Thanks for the response. I saw that I could set "heartbeat_interval" equal to whatever value I wanted in pika.ConnectionParameters but the client heartbeat_interval could not be larger than the rabbit server's heartbeart. How would I go about increasing my rabbit server's heartbeat so I could set the client's equal to it? Would I need to create the rabbit.config file in /etc/rabbitmq and then set the value there? If so, is heartbeat_interval = 600 valid syntax for the config file? Just the one line like and follow rules here? rabbitmq.com/configure.html
– UCProgrammer
Aug 8 at 18:46






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard