-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
717 additions
and
2,000 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.apache.seata</groupId> | ||
<artifactId>spring-dubbo-seata-tcc</artifactId> | ||
<version>2.1.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-dubbo-seata-tcc</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- log dependency start --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.32</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.13</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>1.7.32</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>log4j-over-slf4j</artifactId> | ||
<version>1.7.32</version> | ||
</dependency> | ||
<!-- log dependency end --> | ||
|
||
<dependency> | ||
<groupId>org.apache.seata</groupId> | ||
<artifactId>seata-all</artifactId> | ||
<version>2.1.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
<version>5.3.20</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.13.5</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo</artifactId> | ||
<version>3.1.11</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-remoting-zookeeper-curator5</artifactId> | ||
<version>3.1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.curator</groupId> | ||
<artifactId>curator-x-discovery</artifactId> | ||
<version>5.1.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.curator</groupId> | ||
<artifactId>curator-test</artifactId> | ||
<version>5.1.0</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
</project> |
73 changes: 73 additions & 0 deletions
73
saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/ResultHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.action; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* The type Result holder. | ||
* | ||
* @author zhangsen | ||
*/ | ||
public class ResultHolder { | ||
|
||
private static Map<String, String> actionOneResults = new ConcurrentHashMap<String, String>(); | ||
|
||
private static Map<String, String> actionTwoResults = new ConcurrentHashMap<String, String>(); | ||
|
||
/** | ||
* Set action one result. | ||
* | ||
* @param txId the tx id | ||
* @param result the result | ||
*/ | ||
public static void setActionOneResult(String txId, String result) { | ||
actionOneResults.put(txId, result); | ||
} | ||
|
||
/** | ||
* Get action one result string. | ||
* | ||
* @param txId the tx id | ||
* @return the string | ||
*/ | ||
public static String getActionOneResult(String txId) { | ||
return actionOneResults.get(txId); | ||
} | ||
|
||
/** | ||
* Set action two result. | ||
* | ||
* @param txId the tx id | ||
* @param result the result | ||
*/ | ||
public static void setActionTwoResult(String txId, String result) { | ||
actionTwoResults.put(txId, result); | ||
} | ||
|
||
/** | ||
* Get action two result string. | ||
* | ||
* @param txId the tx id | ||
* @return the string | ||
*/ | ||
public static String getActionTwoResult(String txId) { | ||
return actionTwoResults.get(txId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionTwo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.action; | ||
|
||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
import org.apache.seata.rm.tcc.api.BusinessActionContextParameter; | ||
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; | ||
|
||
import java.util.List; | ||
|
||
public interface TccActionTwo { | ||
|
||
/** | ||
* Prepare boolean. | ||
* | ||
* @param actionContext the action context | ||
* @param b the b | ||
* @param list the list | ||
* @return the boolean | ||
*/ | ||
boolean prepare(BusinessActionContext actionContext, String b, List list); | ||
|
||
/** | ||
* Commit boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
public boolean commit(BusinessActionContext actionContext); | ||
|
||
/** | ||
* Rollback boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
public boolean rollback(BusinessActionContext actionContext); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...e/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionOneImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.action.impl; | ||
|
||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
import org.apache.seata.rm.tcc.api.BusinessActionContextParameter; | ||
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; | ||
import org.apache.seata.action.ResultHolder; | ||
import org.apache.seata.action.TccActionOne; | ||
import org.springframework.util.Assert; | ||
|
||
public class TccActionOneImpl implements TccActionOne { | ||
|
||
@Override | ||
@TwoPhaseBusinessAction(name = "DubboTccActionOne", commitMethod = "commit", rollbackMethod = "rollback") | ||
public boolean prepare(BusinessActionContext actionContext,@BusinessActionContextParameter(paramName = "a") int a) { | ||
String xid = actionContext.getXid(); | ||
System.out.println("TccActionOne prepare, xid:" + xid + ", a:" + a); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean commit(BusinessActionContext actionContext) { | ||
String xid = actionContext.getXid(); | ||
Assert.isTrue(actionContext.getActionContext("a") != null); | ||
System.out.println("TccActionOne commit, xid:" + xid + ", a:" + actionContext.getActionContext("a")); | ||
ResultHolder.setActionOneResult(xid, "T"); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean rollback(BusinessActionContext actionContext) { | ||
String xid = actionContext.getXid(); | ||
Assert.isTrue(actionContext.getActionContext("a") != null); | ||
System.out.println("TccActionOne rollback, xid:" + xid + ", a:" + actionContext.getActionContext("a")); | ||
ResultHolder.setActionOneResult(xid, "R"); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.