Detecting closure of connection or channel

45 views
Skip to first unread message

Markus

unread,
Mar 2, 2026, 10:07:38 AM (2 days ago) Mar 2
to rabbitmq-users
Hi,

we are using the topic permissions for restricting bindings and publishings on RabbitMQ. If now client performs a read or write that violates the topic permissions, the access is correctly refused.

We are working with the amqp-client developed in Java. We detected that then the channel that violates the topic permission is closed. As we want to have a reconnection or a clean shutdown of the connection and maybe a reconnect, it would be good to detect this. Checking the methods, we saw that we can add a ShutdownExceptionListener on the channel and on the connection. When now a topic permission violations happens the listener of the channel is called which would allow us to reconnect. But if the connection is closed (e.g., via administrator over the UI), both listeners for the connection and for the channel are triggered.

Thus, is there a suitable way to detect if the channel is closed, e.g., because of a topic permission violation or via the connection (error or manual close) as we do not want to unnecessarily perform reconnections.

Best regards,
Markus

Lucas Weis Polesello

unread,
Mar 2, 2026, 10:14:44 AM (2 days ago) Mar 2
to rabbitmq-users
Hi Markus,

I don't believe RabbitMQ sends a `Reason` or anything special for channel shutdown. Usually `connections` do have a text message explaining why they got closed. If the channel is closed due to connection closed, assuming you are using the same connection object, if should fail right away - not even reaching the broker.
Reply all
Reply to author
Forward
0 new messages