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.
There is now a connection close callback that can be used to track when the lib knows the connection has been closed:
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
await
ing 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 thesocket.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.