[rabbitmq-discuss] How to achieve HA consumers?

Francesco Mazzoli francesco at rabbitmq.com
Fri Aug 31 12:27:34 BST 2012


Hi,

This is done easily by having acks enabled.  When the first consumer dies, the
unacked messages will be requeued, and the second consumer can start consuming.

Now, the only issues is for the second consumer to find out when to start
consuming.  This can be done in a multitude of ways, but we'll propose two:

  * The second consumer polls the first in some way and starts consuming when it
    realises the first consumer is dead.  This is simple and should serve you
    right, but it's not that nice performance wise.

  * You create a second queue that we'll call "token queue", and you publish one
    dummy message in it, with acks enabled.  Then, a consumer wishing to consume
    from your queue, will:

      - Consume from the token queue
      - Start consuming from the actual queue
      - When shutting down, publish a dummy message to the token queue

    In this way your token queue will act a semaphore that will guarantee
    exclusive access to the queue.  When a consumer die, the message in the
    token queue will be requeued, and the next consumer will be able to consume
    it and then start consuming from the other queue.

    This method scales to an arbitrary number of consumers.

I hope this suggestions help.

--
Francesco * Often in error, never in doubt


More information about the rabbitmq-discuss mailing list