Search code examples
rabbitmqspring-amqpfifo

RabbitMQ and FIFO when multiple consumers


We have multiple consumer to handle create messages, but we want to ensure the FIFO order so if we create a product A, we must to reject the next creations of product A.

The problem is because we have several consumers to treate this type of messages it is possible to have consumer 1 that finish after consumer 2. For exemple the message 1 contains more data to be saved compared to mesage 2 for the same product.

Running RabbitMQ with multiple consumers violates FIFO principle of queue. Is there a way to avoid this with RabbitMQ or we must to orientate our architecture in a manner that the control is more Java threatement oriented ?

Thanks


Solution

  • Running RabbitMQ with multiple consumers violates FIFO principle of queue.

    No, it doesn't. The messages are delivered in FIFO order. Multiple consumers will result in messages being delivered round-robin among them, but they are still delivered in FIFO order.

    If you want to retain this order, you must use only one consumer, or coordinate work between your consumer processes.