Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:14:34+00:00 2026-05-29T05:14:34+00:00

I have some scripts, using pika.SelectConnection to communicate with RabbitMq server. Is there anyway

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:14:35+00:00Added an answer on May 29, 2026 at 5:14 am

    I have lots of scripts which use the following approach to reconnecting:

     while True:
         try:
             mqExch.channel.connection.drain_events(timeout=25)
         except socket.timeout:
             hb.beat() # let our supervisor know we are not hung
    

    It’s not using pika, but Kombu, nevertheless the principles can be applied. The drain_events method 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some TCL scripts on the server . I am using a client
I am trying to understand some scripts that I have inherited and make use
I'm using SQL*Plus 9.2 on Oracle 10g enterprise. I have created some scripts that
I'm using a string builder to build some SQL Scripts. I have a few
I have several init.d scripts that I'm using to start some daemons. Most of
We have a few C++ solutions and we run some build scripts using batch
I have some automatically generated Ant build scripts that I need to use to
I'm using mostly Javascript on my scripting. I have some scripts which do several
I have some scripts that ought to have stopped running but hang around forever.
I have some ksh scripts which I'd like to convert to run with bash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.