Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saga 中补偿业务的实现。 #554

Open
hanxiaolong-github opened this issue Jul 15, 2022 · 0 comments
Open

saga 中补偿业务的实现。 #554

hanxiaolong-github opened this issue Jul 15, 2022 · 0 comments

Comments

@hanxiaolong-github
Copy link

hanxiaolong-github commented Jul 15, 2022

你好:
我看demo 中saga的例子是扣减库存,大概总结下来是:
transaction 1: set amount = amount+1 where id = 1;
transaction 2: set amount = amount +2 where id = 1;
当transaction 1 发生错误,需要补偿的时候:业务端 写个方法是: set amount = amount-1 where id = 1;
当transaction 2 发生错误,需要补偿的时候:业务端 写个方法是: set amount = amount-2 where id = 1;
这是正确的。
如果换成字符串好像就不对了,例如:
transaction 1: set name = 'n1' where id = 1;
transaction 2: set name = 'n2' where id = 1;
当transaction 1 发生错误,需要补偿的时候:业务端 写个方法是: set name = null where id = 1;
当 transaction 2 补偿的时候 set name = 'n1' where id = 1。最后name 变成了 n1 了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant