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

Provide saga functionality (based on interceptors) #1681

Closed
wants to merge 2 commits into from
Closed

Provide saga functionality (based on interceptors) #1681

wants to merge 2 commits into from

Conversation

zhongfuhua
Copy link
Contributor

Ⅰ. Describe what this PR did

Provide saga functionality (based on interceptors)

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Existing test cases

Ⅳ. Describe how to verify it

1、Saga interface

public interface SagaServiceOne {

    @SagaCompensiable(name = "sagaDubboServiceOne", rollback = "rollback")
    boolean commit(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "a") int a);

    boolean rollback(BusinessActionContext actionContext);
}

2、Implementation of Saga interface

public class SagaServiceOneImpl implements SagaServiceOne {
    
    @Override
    public boolean commit(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "a") int a) {
        String xid = actionContext.getXid();
        System.out.println("SagaServiceOne prepare, xid:" + xid + ", a:" + a);
        
        List arrayList = new ArrayList();
        arrayList.add("d1");
        arrayList.add("d2");
        sagaServiceThree.commit(null, "t", arrayList, "d");
        return true;
    }
    
    @Override
    public boolean rollback(BusinessActionContext actionContext) {
        String xid = actionContext.getXid();
        System.out.println("SagaServiceOne rollback, xid:" + xid + ", a:" + actionContext.getActionContext("a"));
        ResultHolder.setActionOneResult(xid, "R");
        return true;
    }

}

3、Business Opens Global Transactions

@GlobalTransactional
public String doTransactionCommit() {
	boolean result = sagaServiceOne.commit(null, 1);
	if (!result) {
		throw new RuntimeException("SagaActionOne failed.");
	}
	return RootContext.getXID();
}

Ⅴ. Special notes for reviews

@zhongfuhua zhongfuhua changed the title 0.8.1 Provide saga functionality (based on interceptors) Sep 20, 2019
@codecov-io
Copy link

codecov-io commented Sep 20, 2019

Codecov Report

Merging #1681 into 0.8.1 will decrease coverage by 1.26%.
The diff coverage is 15.34%.

Impacted file tree graph

@@             Coverage Diff              @@
##              0.8.1    #1681      +/-   ##
============================================
- Coverage     47.17%   45.91%   -1.27%     
- Complexity     1779     1809      +30     
============================================
  Files           362      380      +18     
  Lines         13237    13763     +526     
  Branches       1641     1713      +72     
============================================
+ Hits           6245     6319      +74     
- Misses         6316     6742     +426     
- Partials        676      702      +26
Impacted Files Coverage Δ Complexity Δ
...ommon/src/main/java/io/seata/common/Constants.java 50% <ø> (ø) 1 <0> (ø) ⬇️
...ta/spring/annotation/GlobalTransactionScanner.java 50.45% <0%> (-0.95%) 17 <0> (ø)
...main/java/io/seata/rm/saga/remoting/Protocols.java 0% <0%> (ø) 0 <0> (?)
...rm/saga/remoting/parser/DefaultRemotingParser.java 0% <0%> (ø) 0 <0> (?)
...va/io/seata/spring/saga/SagaActionInterceptor.java 0% <0%> (ø) 0 <0> (?)
...src/main/java/io/seata/rm/saga/TwoPhaseResult.java 0% <0%> (ø) 0 <0> (?)
.../java/io/seata/server/coordinator/DefaultCore.java 58.65% <0%> (-1%) 24 <0> (ø)
...a/src/main/java/io/seata/rm/saga/SAGAResource.java 0% <0%> (ø) 0 <0> (?)
.../saga/remoting/parser/DubboRemotingSagaParser.java 0% <0%> (ø) 0 <0> (?)
...ain/java/io/seata/rm/saga/SAGAResourceManager.java 0% <0%> (ø) 0 <0> (?)
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 451bb01...07269d0. Read the comment docs.

@l81893521 l81893521 changed the base branch from 0.8.1 to develop September 26, 2019 03:28
@long187
Copy link
Contributor

long187 commented Feb 27, 2020

@zhongfuhua 请问你钉钉号多少?交流一下基于注解+拦截器的Saga实现

@zhongfuhua
Copy link
Contributor Author

zhongfuhua commented Mar 1, 2020 via email

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@funky-eyes
Copy link
Contributor

Additionally realized #5300

@funky-eyes funky-eyes closed this Nov 27, 2023
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

Successfully merging this pull request may close these issues.

5 participants