[erlang-questions] Make sure that there is only one consumer connected to the RabbitMQ queue

Tim Watson watson.timothy@REDACTED
Wed Mar 13 15:23:02 CET 2013


Hi Max,

On 13 Mar 2013, at 14:07, Max Bourinov wrote:
> I have multiple nodes that might connect to the certain queue at my RabbitMQ server. I need to make sure that only the first of them will connect and all others will fail. Queue should not be deleted when currently connected node goes down.
> 
> I think that exclusive = true and auto-delete = false will do the work. Am I right?
> 

From http://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.declare.exclusive:

"bit exclusive

Exclusive queues may only be accessed by the current connection, and are deleted when that connection closes. Passive declaration of an exclusive queue by other connections are not allowed."

An exclusive queue will be deleted when the connection closes, whereas the auto-delete flag is for ensuring the queue is deleted once all consumers have finishing using it. Also, exclusive queues will exist only _for_ the current connection - i.e., no other connection will know about them - so they're not the right abstraction for limiting access to a shared resource. In fact, I'm not sure if AMQP provides a mechanism to do what you want.

Is there another way to approach this requirement, or is this specific behaviour a vital part of it? There are probably ways you could layer this on top of AMQP if you're using the erlang-client, but I suspect you'll have more luck trying to select a different routing topology rather than enforcing connectivity rules that the specification doesn't support.

Cheers,

Tim Watson
Staff Engineer
RabbitMQ / VMWare


More information about the erlang-questions mailing list