Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

rabbitmq - How does the broker make sure that message is consumed only by one consumer?

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?

question from:https://stackoverflow.com/questions/65922912/how-does-the-broker-make-sure-that-message-is-consumed-only-by-one-consumer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...