-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check is a connection ok? #877
Comments
Hello @zhangzx7054 - Since you are using a
If you use one of the asynchronous adapters for your client code, you will also see the heartbeat mechanism detect lost connections. Please refer to the example code. |
@lukebakken Is there a way to directly trigger a heartbeat My current workaround to "do something with the channel" is to check for the existence of an exchange, but I would prefer to simply force a heartbeat to show RMQ that my process is still alive.
More specifically, I would like to be able to manually send a heartbeat frame from a BlockingConnection.
|
If you periodically call In practice, you have to be prepared any time for a dropped connection (RabbitMQ issue, network issue, etc.). Checking a connection just before sending something is not guarantee that connection won't be lost while your're sending, so you need to anticipate re-connection and retries. For example, see _RETRY_ON_AMQP_ERROR decorator and _ChannelManager wrapper of AMQP client |
We cannot directly use the `is_open` property that pika's BlockingConnection provides because the heartbeat mechanism does not detect closed connections itself. See: pika/pika#877 This lead to a lot of ConnectionClosed errors in the API which was the main cause of almost all the Sentry errors.
I tried to use channel.is_open and connetcion.is_open to get the connection's and channel's status, but failed.
The return value is always True, even though I stopped rabbitmq server.
Here is my test code.
Here is the print log. When rabbitmq server stops, the print log is still the same as below.
The text was updated successfully, but these errors were encountered: