I have some scripts, using pika.SelectConnection to communicate with RabbitMq server.
Is there anyway to make those scripts trying automatically reconnect to rmq server, in case when server gone down, while script working?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I have lots of scripts which use the following approach to reconnecting:
It’s not using pika, but Kombu, nevertheless the principles can be applied. The
drain_eventsmethod is the core of message consuming, i.e. it loops forever receiving messages and running a callback to process the message. As you can see here I have the low level socket library timing out every 25 seconds. With some libraries I had to patch a couple of lines of code to get this behaviour to work without crashing inside the module.In any case, the heartbeat that is sent by hb.beat is monitored by a supervisor process and this process will kill the script if there are too many failures in too short a time span. After killing the script, the supervisor restarts it. This has worked well in dealing with intermittent network errors or MQ broker restarts. While I could have made my script do the reconnecting, it was simpler to kill and restart.