This topic describes the concept and typical scenarios of the exactly-once delivery semantics of Message Queue for Apache RocketMQ, to help you understand how a message is processed only once by the consumer.
What is exactly-once delivery semantics?
Exactly-once means that a message sent to a messaging system is processed only once by the consumer, even if the producer re-sends the message.
Exactly-once delivery semantics is an ideal state of message transfer in messaging systems and stream computing systems. However, this ideal state is rarely implemented in the industry, because it depends on the coordination between the message broker, message client, and user consumption logic. For example, if your consumer client fails after processing a message, the client may process the message again after a restart, because the consumer offset is not synchronized to the message broker.
Exactly-once delivery semantics is controversial in the industry. Many refer to the FLP Impossibility theory or other consistency rules to challenge the validity of exactly-once delivery semantics. In fact, in certain scenarios, exactly-once delivery semantics is not difficult to implement. Its implementation only seems complex because the essence of the topic is not described accurately.
To make the consumption result of each message take effect only once in your business system, ensure the consumption idempotence of the same message. The use of the exactly-once delivery semantics of Message Queue for Apache RocketMQ ensures that the consumption result of a message (the message processing result on the consumer) exists and takes effect only once in the database system.
For more information about how to use the exactly-once delivery semantics, see Use the exactly-once delivery semantics to send and subscribe to messages.