Detecting closure of connection or channel

111 views
Skip to first unread message

Markus

unread,
Mar 2, 2026, 10:07:38 AMMar 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 AMMar 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.

Markus

unread,
Mar 5, 2026, 5:01:54 AMMar 5
to rabbitmq-users
Hi Lucas,

thank you for your answer. I think our use case is somewhat different. When there is a topic permission violation, the channel is closed by RabbitMQ but not the connection. Where on the other the side if the connection is closed, also the channel is closed first and then the connection. Thus, we cannot identify which case happened. In the debugger you can detect who is closing via the class hierarchy, either AMQP$Channel$Close or AMQP$Connection$Close but using this is not clean solution. Also the same exception is thrown when a clean shutdown happens.

Please note that the topic permission violation is only one scenario for channel errors but we would like to be able to differentiate the different scenarios and doing this via the message string is not a good approach.

Therefore, we would like to know if there is a way to differentiate connection closures from channel closures as well as real exceptions and clean shutdowns.

Best regards,
Markus
Reply all
Reply to author
Forward
0 new messages