0
votes

I have a queue and have two consumers c1 and c2. My two consumers are up and running. When a message is published to the queue, how does the JMS broker (RabbitMQ) make sure that message is consumed only by one consumer?

1
The answer to this question is entirely dependent on how RabbitMQ is implemented. Therefore, I'm removing the general jms and message-queue tags.Justin Bertram

1 Answers

0
votes

Existing messaging systems(RabbitMQ/Kafka/Kinesis/SQS) can't guarantee the message consumption, however they can guarantee the message delivery.

However, a message consumption by a single consumer can be accomplished in the consumer code and positively acknowledging the message to RabbitMQ that the message is processed by a consumer. In case, there is validation error/external API call error or consumer exited with unknown error during processing, RabbitMQ redelivers the message with re-delivery flag in which case the consumer code should check for earlier message processing against a distributed Cache/DataBase and then take further action. This way, message consumption can be ensured once. All the messaging systems redeliver a message under various cases, hence its advisable to code for duplicate processing.

In your case 'single active consumer scenario, RabbitMQ re-delivers a messages to currently active consumer though you may have multiple instances of consumer running which are in a standby mode.