Skip to content

Commit

Permalink
feat: del saga-spring case
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlgod committed Oct 26, 2024
1 parent 160cb4b commit 167a62f
Show file tree
Hide file tree
Showing 43 changed files with 717 additions and 2,000 deletions.
116 changes: 116 additions & 0 deletions saga-sample/spring-dubbo-seata-tcc/pom.xml
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>
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.seata.provider.action;
package org.apache.seata.action;

import java.math.BigDecimal;
import java.util.Map;
import org.apache.seata.rm.tcc.api.BusinessActionContext;
import org.apache.seata.rm.tcc.api.BusinessActionContextParameter;
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
* Balance Actions
*/
public interface BalanceAction {
public interface TccActionOne {

/**
* reduce
* Prepare boolean.
*
* @param businessKey
* @param amount
* @param params
* @return
* @param actionContext the action context
* @param a the a
* @return the boolean
*/
boolean reduce(String businessKey, BigDecimal amount, Map<String, Object> params);
boolean prepare(BusinessActionContext actionContext, int a);

/**
* compensateReduce
* Commit boolean.
*
* @param businessKey
* @param params
* @return
* @param actionContext the action context
* @return the boolean
*/
boolean compensateReduce(String businessKey, Map<String, Object> params);
boolean commit(BusinessActionContext actionContext);

/**
* Rollback boolean.
*
* @param actionContext the action context
* @return the boolean
*/
boolean rollback(BusinessActionContext actionContext);
}
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);

}
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;
}
}
Loading

0 comments on commit 167a62f

Please sign in to comment.