RabbitMQ - Resolve "cannot obtain exclusive access to locked queue"

Let's say something like this is being captured in rabbit.log.

2022-04-08 18:58:24.037 [warning] <0.16434.227> Error purging queue: cannot obtain exclusive access to locked queue 'amq.gen-q8gYvM_2dovjoQPkC-V2HA' in vhost 'foo'.
It could be originally declared on another connection or the exclusive property value does not match that of the original declaration.


There are a few things that could cause this to occur, such as:


This typically suggests that a dynamic shovel was created to move messages from an exchange to a queue.


If the shovel source is an exchange, an exclusive queue will be created and the source exchange should be bound to the exclusive queue. An exclusive queue is a sort of temporary queue that will be removed after the shovel is terminated. The exclusive queue will begin with "amq.gen". The rabbitmqctl list_queues command can be used to list the exclusive queues. In this example, there is an exclusive queue in the foo virtual host.

~]$ rabbitmqctl list_queues name exclusive --vhost foo --formatter json | python -m json.tool
        "exclusive": true,
        "name": "amq.gen-q8gYvM_2dovjoQPkC-V2HA"


Likewise, the rabbitmqctl list_bindings command should show that the source exchange is bound to the exclusive queue.

~]# rabbitmqctl list_bindings --vhost foo --formatter json | python -m json.tool
        "arguments": [],
        "destination_kind": "queue",
        "destination_name": "amq.gen-q8gYvM_2dovjoQPkC-V2HA",
        "routing_key": "key002",
        "source_kind": "exchange",
        "source_name": "exchange001"


The rabbitmq shovel_status command can be used to check the state of the shovel.

~]$ rabbitmqctl shovel_status --formatter json | python -m json.tool
        "destination": "amqps://rabbit.example.com:5671/%2f",
        "destination_protocol": "amqp091",
        "destination_queue": "queue001",
        "last_changed": "2022-04-03 03:49:29",
        "name": "shovel001",
        "source": "amqps://rabbit.example.com:5671/%2f",
        "source_exchange": "exchange001",
        "source_exchange_key": "key002",
        "source_protocol": "amqp091",
        "state": "running",
        "termination_reason": "",
        "type": "dynamic",
        "vhost": "foo"


Sometimes, you might just want to restart the shovel to see if this has any impact.

rabbitmqctl restart_shovel --vhost foo shovel001


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter ac2f4 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |