Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of distributed transaction in rocketMq

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of distributed transactions in rocketMq, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.

Distributed transaction

First review the transaction, such as bank transfer, A to B transfer 100 yuan, this action includes two steps:

An account minus 100 yuan

B account plus 100 yuan

Put these two steps in one transaction to ensure complete success or complete failure.

In a single service, it is easy to solve, and a database transaction is completed, but in a distributed system, these two steps may be handled separately by different sub-services, which involves the concept of distributed transaction.

RocketMQ provides support for transactions, which can help us complete the processing of distributed transactions.

RocketMQ solution

For example, transaction T includes two logical steps, T1 and T2, and system An and B execute T1 and T2, respectively.

A sends an acknowledgement message M to RocketMQ (this message will not be sent to BMagol RocketMQ to keep this message first), and then executes T1Magi A to submit a second confirmation to RocketMQ based on the execution result.

If the T1 execution is successful, then the message M will be marked as deliverable, and B will be able to receive it. When B receives M, it will know that A must have completed the T1 part of the work, and B only needs to ensure that it completes T2; if the T1 execution fails, then the message M will be deleted by RocketMQ and B will not receive it.

In this way, the distributed transaction is completed.

The message to be confirmed is called "half message".

There is a problem. What if A fails to send a second confirmation to RocketMQ for some reason?

RocketMQ has a review mechanism, that is, after a period of time, when it finds that the confirmation message has not been confirmed, it will take the initiative to ask producer, and producer will give feedback based on the execution result of the local transaction, whether it is successful or failed.

Detailed step instructions

Producer sends message of transaction type to MQ.

When the MQ receives successfully, it returns an acknowledgement message to the Producer, and the half message is formed.

Producer performs local transaction logic.

Producer makes a second confirmation to MQ based on the local execution result (commit submission or rollback rollback). If it is commit, then MQ makes the previous half message become a message that can be consumed by Consumer, and Consumer receives the message; if it is rollback, then MQ discards the previous half message.

When step 4 is missing, MQ asks Producer to check back.

Producer views the results of local transaction execution.

Producer sends a confirmation message to MQ based on the feedback from step 6

Thank you for reading this article carefully. I hope the article "sample Analysis of distributed transactions in rocketMq" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report