Skip to content
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 do I check connection status before publish #107

Open
hritik09 opened this issue Sep 3, 2018 · 1 comment
Open

how do I check connection status before publish #107

hritik09 opened this issue Sep 3, 2018 · 1 comment

Comments

@hritik09
Copy link

hritik09 commented Sep 3, 2018

No description provided.

@JustinTArthur
Copy link

JustinTArthur commented Feb 7, 2019

There is now a connection close callback that can be used to track when the lib knows the connection has been closed:

connect(
    host='localhost',
    port=5672,
    username='guest', password='guest',
    virtual_host='/',
    on_connection_close=stop_publishing_things  # <----
)

If you're worried about the other side having closed the connection without you knowing, you'd have to send something that would trigger a connection reset response or that would time out before you got your expected response. The only way to do this at the app level would be using the AMQP heartbeat command. At the moment, asynqp does not expose this in a convenient way for awaiting a valid heartbeat response.

This can be done at the transport level using TCP keep-alive, which will allow your on_connection_close callback to be called once the close is detected at the TCP level. You can grab the socket using connection.transport.get_extra_info('socket'), then set the desired keep-alive options using the socket.setsockopt method. Aggressive keepalive settings could be used to discover a closed connection early, but this is still not convenient for knowing for-sure before making a publish, such as from a docker container or serverless runtime that has just been unpaused after a long freeze. At some point, maybe asynqp will expose the heartbeat for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants