The concept is introduced
Half(Prepare) Message: the Message cannot be delivered for the time being. When a message is successfully sent to the MQ server, but the server does not receive a second acknowledgement of the message from the producer, the message is marked as temporarily undeliverable. A message in this state is called a half-committed message.
Message Status Check: A second transaction confirmation Message may be lost when the network is disconnected or the producer application is restarted. When the MQ server finds that a message has remained half-committed for a long time, it sends a request to the message producer to check the final status (commit or rollback) of the message.
Transactional message execution process
The RocketMQ transaction execution flow is shown below:
- The producer sends a Prepare message to the MQ server.
- After the Prepare message is successfully sent, the local transaction is executed.
- Send a commit or rollback message to the MQ server based on the result of the local transaction.
- If the commit/rollback message is lost or pending during the execution of a local transaction by the producer. The MQ server checks that messages are sent to each producer in the same group to obtain the status of the local transaction execution of the message.
- Generate a reply commit/rollback message based on the local transaction status.
- Committed messages will be served for consumer consumption, but rollback messages will be discarded by the MQ server.
Design details
An overview of RocketMQ’s transactional messaging design architecture is shown below: