当前位置:网站首页>Distributed transaction - Final consistency scheme based on message compensation (local message table, message queue)
Distributed transaction - Final consistency scheme based on message compensation (local message table, message queue)
2022-06-28 04:49:00 【May Hacker】
Preface
The final consistency scheme based on message compensation is an implementation of distributed transactions , It also includes the local message table 、 There are two ways of message queuing .
One 、 Local message table
The core idea is to split the distributed transaction into local transaction , Local message tables achieve final consistency .

- step 1 and 2, The system receives the user's order request , Write the order business data into the order table , At the same time, write the message data corresponding to the order into the local message table , The order table and the local message table are in the same database , Update the order and store the message as the same local transaction , Database transaction processing , Either they all succeed , Or they all failed .
- step 345, The order service sends a message to the message queue , The inventory service received a message , Perform inventory operations , Update inventory data
- step 6 and 7, Business processing results are returned , After the order service receives the result , Set the data in the local message table to the completion status or delete the data .
- step 8, Another scheduled task , Scan local message table regularly , See if there are any unfinished tasks , Try again if any .
Advantages and disadvantages
- Implement a simple , Low development cost
- The order table and the local message table are in the same database
Two 、 Message queues that support transactions
RMQ Support transaction messages , It is similar to the common database transaction process , The producer produces a transaction message , Wait for the local operation of the producer ok 了 , Will send to MQ Server Send submission confirmation .
under these circumstances , Transaction messages are initially thrown into the message queue and cannot be consumed , Only when the transaction message is committed , This information can be consumed by consumers .
Empathy , If rollback 了 ,RMQ The message will be deleted from the message queue .

- Producers produce messages to MQ, Not submitted at this time , Call this message HalfMsg, Half message
- MQ Received the message , Will give the producer a OK confirm
- Producers perform local transactions
- According to the result of local transaction execution, the MQ Submit commit perhaps rollback,MQ according to commit perhaps rollback Operate on the message accordingly , To consume or discard
- If the producer submits commit perhaps rollback Submission timeout , That is, step 4 does not receive a request from the producer ,MQ The callback checks the message
- MQ The callback checks the status of the local transaction
Reference resources
https://www.jianshu.com/p/e31d9ebed201
边栏推荐
- 有人用cdc同步到mysql发生过死锁吗?
- Multithreading and high concurrency III: AQS underlying source code analysis and implementation classes
- Difference between curdate() and now()
- 易周金融 | Q1手机银行活跃用户规模6.5亿;理财子公司布局新兴领域
- Principle of event delegation
- How do I get the STW (pause) time of a GC (garbage collector)?
- Go语言学习教程(十四)
- Audio and video technology development weekly
- Function and working principle of controller
- [matlab traffic light identification] traffic light identification [including GUI source code 1908]
猜你喜欢

Necessary skills for test and development: actual combat of security test vulnerability shooting range

Mask's miserable and inspirational childhood, who is introverted by campus violence

Introduction to SQLSERVER database

Sword finger offer 49 Ugly number (three finger needling technique)

恭喜我自己,公众号粉丝破万

Google Earth Engine(GEE)——全球洪水数据库 v1 (2000-2018年)

How to traverse collections Ordereddict, taking it and forgetting items

27 years, Microsoft IE is over!

A doctor's 22 years in Huawei (full of dry goods)

Matlab exercises -- exercises related to symbolic operation
随机推荐
Mask's miserable and inspirational childhood, who is introverted by campus violence
Performance optimization and implementation of video codec
Digital promising, easy to reach, Huawei accelerates the layout of the commercial market with "five pole" star products
Bitlock recovery occurs in win 10, and the blue screen error code is 0x1600007e
Why are cloud vendors targeting this KPI?
为什么大厂不让使用undefined
inherit
Matlab exercises -- routine operation of matrix
Project practice! Teach you JMeter performance test hand in hand
如何遍历collections.OrderedDict,服了又忘记items
Detailed reading of the thesis: implementing volume models for handowriting text recognition
How to traverse collections Ordereddict, taking it and forgetting items
阿里P8倾情推荐,Fiddler抓包工具实战篇(一)
[CSP-J2020] 优秀的拆分
[matlab traffic light identification] traffic light identification [including GUI source code 1908]
10: 00 interview, came out at 10:02, the question is really too
Function and working principle of controller
Multithreading and high concurrency II: detailed introduction to volatile and CAS
Has anyone ever used CDC to synchronize to MySQL with a deadlock?
27 years, Microsoft IE is over!