Reputation: 8859
Having trouble wrapping my ahead around the differences between exclusive queue
and exclusive consumer
, and was wondering if I had this correct.
Let's say I have a queue
, consumer1
, and consumer2
.
My understanding is:
exclusive queue
If queue
is exclusive queue
and was created by consumer1
, only consumer1
can access the queue, and when consumer1
goes down, queue
is deleted. It sounds like messages are then lost.
exclusive consumer
If queue
is NOT exclusive and was created by consumer1
, then both consumer1
and consumer2
can read from it. If consumer1
goes down, consumer2
can pick up where it left off. If consumer1
is exclusive consumer
and starts a subscription first, then consumer2
cannot access queue
, while it is locked by consumer1
.
exclusive queue
sounds like a weird use case to me whereas exclusive consumer
sounds like the proper solution for "only 1 consumer should process from the queue at a time".
Upvotes: 5
Views: 4179
Reputation: 19328
I think the difference between them is that for exclusive
queue it can only be consumed by consumers
that are on the same connection which is used for declaring the queue. When this connection is closed or disconnected, the exclusive
queue is automatically closed by rabbitmq
. The use case for it is that you usually want the queue to be destroyed when the exclusive
(private) consumer exit or disconnect.
Whereas the use case for exclusive
consumer on a normal queue
is slightly different. The private consumer may be gone or disconnected but another consumer can be the successor of the next exclusive
consumer, and it may not have to be on the same rabbitmq
connection as the one used for declaring the queue
.
Essentially both use cases are about allowing exclusive
access to the queue but the latter is less strict.
Upvotes: 7