Message queue realizes distributed transaction

The "transaction" in the message queue mainly solves the problem of data consistency between the message producer and the message consumer.
E-commerce order step
1. Generate order
2. Delete shopping cart
In a distributed system, any step may fail, and there may be inconsistencies between the order data and the shopping cart data. For example,
1. The order is created but not cleaned up. Shopping cart;
2. The order is not created successfully, but the goods in the shopping cart are cleared.

The order system sends the order message to the message queue and starts the transaction (the order message is not visible to the shopping cart system at this time). The
order system executes a local transaction, generates the order successfully, and sends the message to the message queue to make its message visible to the
shopping cart system. Shopping cart system consumption Messages
In the transaction implementation in RocketMQ, a transaction back-check mechanism is added to solve the problem of transaction message submission failure .
Broker will periodically check the status of the local transaction corresponding to this transaction on the Producer, and then decide to submit or return according to the result of the back-check. Roll this transaction.

Guess you like

Origin blog.csdn.net/u010010600/article/details/108740626