Search code examples
rabbitmqstomp

Several STOMP consumers from queue processing each message once


I have a queue on RabbitMQ and an app consuming from that queue via STOMP. I would like to have 2 or more instances of my app consuming from the same queue.

How can I consume each message in the queue once and only once? For instance, if I have messages A, B, C in the queue I want my apps to consume the messages likes this:

  • Instance 1: A
  • Instance 2: B,C

And NOT like this:

  • Instance 1: A, B, C
  • Instance 2: A, B, C

Solution

  • You can't configure a "STOMP queue" in RabbitMQ, per se. The STOMP specification does not define what the delivery semantics of destinations should be. As noted in the RabbitMQ documentation you can use a handful of different prefixes to get the semantics you want, e.g.:

    • /exchange -- SEND to arbitrary routing keys and SUBSCRIBE to arbitrary binding patterns;
    • /queue -- SEND and SUBSCRIBE to queues managed by the STOMP gateway;
    • /amq/queue -- SEND and SUBSCRIBE to queues created outside the STOMP gateway;
    • /topic -- SEND and SUBSCRIBE to transient and durable topics;
    • /temp-queue/ -- create temporary queues (in reply-to headers only).