This topic describes the concept and typical scenarios of the Exactly-Once delivery semantics of MQ.
Note: For more information about how to send and receive messages through the Exactly-Once delivery semantics, see Use Exactly-Once delivery semantics.
Exactly-Once means that a message sent to a message 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 message 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 FLP Impossibility theory or other consistency laws to challenge the validity of Exactly-Once semantics. In fact, in certain scenarios, the 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 Exactly-Once delivery semantics by MQ 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. This is the most common business requirement.
In an e-commerce system, the upstream real-time computing module releases product price change messages and asynchronously sends them to the downstream product management module. Then the downstream product management module changes the product prices. In this case, consumption idempotence must be ensured for each message. That is, duplicate price change messages take effect only once, preventing repeated changes of prices.