From 167a62ffcd8ba46d814fff30070d7be64daf37ea Mon Sep 17 00:00:00 2001 From: Jingliu Xiong <928124786@qq.com> Date: Sat, 26 Oct 2024 10:57:06 +0800 Subject: [PATCH] feat: del saga-spring case --- saga-sample/spring-dubbo-seata-tcc/pom.xml | 116 +++++++++++++ .../org/apache/seata/action/ResultHolder.java | 73 +++++++++ .../apache/seata/action/TccActionOne.java} | 39 +++-- .../org/apache/seata/action/TccActionTwo.java | 53 ++++++ .../seata/action/impl/TccActionOneImpl.java | 53 ++++++ .../seata/action/impl/TccActionTwoImpl.java | 68 ++++++++ .../seata/service/TccTransactionService.java | 108 ++++++++++++ .../seata/stater/TccConsumerStarter.java | 62 +++++++ .../seata/stater/TccProviderStarter.java | 56 +++++++ .../src/main/resources/file.conf | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/registry.conf | 0 .../resources/spring/seata-dubbo-provider.xml | 53 ++++++ .../spring/seata-dubbo-reference.xml | 54 ++++++ .../e2e-files/commit.yaml | 1 - .../e2e-files/rollback.yaml | 1 - .../e2e-replace/file.conf | 126 -------------- saga-sample/spring-seata-dubbo-saga/pom.xml | 44 ----- .../spring-seata-dubbo-saga/seata-e2e.yaml | 80 --------- .../spring-seata-dubbo-saga-common/pom.xml | 45 ----- .../src/main/java/seata/e2e/E2EUtil.java | 28 ---- .../spring-seata-dubbo-saga-consumer/pom.xml | 140 ---------------- .../consumer/SagaTransactionStarter.java | 154 ------------------ .../config/DataSourceConfiguration.java | 50 ------ .../config/DubboConsumerConfiguration.java | 71 -------- .../consumer/config/SagaConfiguration.java | 48 ------ .../provider/action/InventoryAction.java | 38 ----- .../action/impl/BalanceActionImpl.java | 58 ------- .../action/impl/InventoryActionImpl.java | 43 ----- .../src/main/resources/sql/h2_init.sql | 74 --------- .../reduce_inventory_and_balance.json | 95 ----------- .../spring-seata-dubbo-saga-provider/pom.xml | 140 ---------------- .../seata/provider/DubboProviderStarter.java | 68 -------- .../seata/provider/action/BalanceAction.java | 46 ------ .../provider/action/InventoryAction.java | 38 ----- .../action/impl/BalanceActionImpl.java | 58 ------- .../action/impl/InventoryActionImpl.java | 43 ----- .../config/DubboProviderConfiguration.java | 61 ------- .../src/main/resources/file.conf | 126 -------------- .../src/main/resources/logback.xml | 13 -- .../src/main/resources/registry.conf | 124 -------------- .../src/main/resources/sql/h2_init.sql | 74 --------- .../reduce_inventory_and_balance.json | 95 ----------- 43 files changed, 717 insertions(+), 2000 deletions(-) create mode 100644 saga-sample/spring-dubbo-seata-tcc/pom.xml create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/ResultHolder.java rename saga-sample/{spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/BalanceAction.java => spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionOne.java} (52%) create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionTwo.java create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionOneImpl.java create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionTwoImpl.java create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/service/TccTransactionService.java create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccConsumerStarter.java create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccProviderStarter.java rename saga-sample/{spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer => spring-dubbo-seata-tcc}/src/main/resources/file.conf (100%) rename saga-sample/{spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer => spring-dubbo-seata-tcc}/src/main/resources/logback.xml (100%) rename saga-sample/{spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer => spring-dubbo-seata-tcc}/src/main/resources/registry.conf (100%) create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-provider.xml create mode 100644 saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-reference.xml delete mode 100644 saga-sample/spring-seata-dubbo-saga/e2e-files/commit.yaml delete mode 100644 saga-sample/spring-seata-dubbo-saga/e2e-files/rollback.yaml delete mode 100644 saga-sample/spring-seata-dubbo-saga/e2e-replace/file.conf delete mode 100644 saga-sample/spring-seata-dubbo-saga/pom.xml delete mode 100644 saga-sample/spring-seata-dubbo-saga/seata-e2e.yaml delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/pom.xml delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/src/main/java/seata/e2e/E2EUtil.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/pom.xml delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/SagaTransactionStarter.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DataSourceConfiguration.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DubboConsumerConfiguration.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/SagaConfiguration.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/InventoryAction.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/sql/h2_init.sql delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/statelang/reduce_inventory_and_balance.json delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/pom.xml delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/DubboProviderStarter.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/BalanceAction.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/InventoryAction.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/config/DubboProviderConfiguration.java delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/file.conf delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/logback.xml delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/registry.conf delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/sql/h2_init.sql delete mode 100644 saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/statelang/reduce_inventory_and_balance.json diff --git a/saga-sample/spring-dubbo-seata-tcc/pom.xml b/saga-sample/spring-dubbo-seata-tcc/pom.xml new file mode 100644 index 000000000..9e0020868 --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/pom.xml @@ -0,0 +1,116 @@ + + + + 4.0.0 + + org.apache.seata + spring-dubbo-seata-tcc + 2.1.0 + jar + + spring-dubbo-seata-tcc + http://maven.apache.org + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.slf4j + slf4j-api + 1.7.32 + + + + ch.qos.logback + logback-classic + 1.2.13 + + + + org.slf4j + jcl-over-slf4j + 1.7.32 + + + org.slf4j + log4j-over-slf4j + 1.7.32 + + + + + org.apache.seata + seata-all + 2.1.0 + + + + org.springframework + spring-jdbc + 5.3.20 + + + + com.fasterxml.jackson.core + jackson-databind + 2.13.5 + + + + + org.apache.dubbo + dubbo + 3.1.11 + + + + org.apache.dubbo + dubbo-remoting-zookeeper-curator5 + 3.1.2 + + + org.apache.curator + curator-x-discovery + 5.1.0 + + + org.apache.curator + curator-test + 5.1.0 + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + + + \ No newline at end of file diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/ResultHolder.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/ResultHolder.java new file mode 100644 index 000000000..cc01e579f --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/ResultHolder.java @@ -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 actionOneResults = new ConcurrentHashMap(); + + private static Map actionTwoResults = new ConcurrentHashMap(); + + /** + * 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); + } + +} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/BalanceAction.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionOne.java similarity index 52% rename from saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/BalanceAction.java rename to saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionOne.java index cb337b29a..d399ae5ca 100644 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/BalanceAction.java +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionOne.java @@ -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 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 params); + boolean commit(BusinessActionContext actionContext); + /** + * Rollback boolean. + * + * @param actionContext the action context + * @return the boolean + */ + boolean rollback(BusinessActionContext actionContext); } diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionTwo.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionTwo.java new file mode 100644 index 000000000..5538aba96 --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/TccActionTwo.java @@ -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); + +} \ No newline at end of file diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionOneImpl.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionOneImpl.java new file mode 100644 index 000000000..78e6dbbba --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionOneImpl.java @@ -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; + } +} diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionTwoImpl.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionTwoImpl.java new file mode 100644 index 000000000..f75ccaa87 --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/action/impl/TccActionTwoImpl.java @@ -0,0 +1,68 @@ +/* + * 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.TwoPhaseBusinessAction; +import org.apache.seata.action.ResultHolder; +import org.apache.seata.action.TccActionTwo; +import org.apache.seata.rm.tcc.api.BusinessActionContext; +import org.apache.seata.rm.tcc.api.BusinessActionContextParameter; +import org.springframework.util.Assert; + +import java.util.List; + +/** + * The type Tcc action two. + * + * @author zhangsen + */ +public class TccActionTwoImpl implements TccActionTwo { + + @Override + @TwoPhaseBusinessAction(name = "DubboTccActionTwo", commitMethod = "commit", rollbackMethod = "rollback") + public boolean prepare(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "b") String b, + @BusinessActionContextParameter(paramName = "c", index = 1) List list) { + String xid = actionContext.getXid(); + System.out.println("TccActionTwo prepare, xid:" + xid + ", b:" + b + ", c:" + list.get(1)); + return true; + } + + @Override + public boolean commit(BusinessActionContext actionContext) { + String xid = actionContext.getXid(); + Assert.isTrue(actionContext.getActionContext("b") != null); + Assert.isTrue(actionContext.getActionContext("c") != null); + System.out.println( + "TccActionTwo commit, xid:" + xid + ", b:" + actionContext.getActionContext("b") + ", c:" + actionContext + .getActionContext("c")); + ResultHolder.setActionTwoResult(xid, "T"); + return true; + } + + @Override + public boolean rollback(BusinessActionContext actionContext) { + String xid = actionContext.getXid(); + Assert.isTrue(actionContext.getActionContext("b") != null); + Assert.isTrue(actionContext.getActionContext("c") != null); + System.out.println( + "TccActionTwo rollback, xid:" + xid + ", b:" + actionContext.getActionContext("b") + ", c:" + actionContext + .getActionContext("c")); + ResultHolder.setActionTwoResult(xid, "R"); + return true; + } + +} diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/service/TccTransactionService.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/service/TccTransactionService.java new file mode 100644 index 000000000..66069bcf7 --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/service/TccTransactionService.java @@ -0,0 +1,108 @@ +/* + * 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.service; + +import org.apache.seata.core.context.RootContext; +import org.apache.seata.spring.annotation.GlobalTransactional; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.seata.action.ResultHolder; +import org.apache.seata.action.TccActionOne; +import org.apache.seata.action.TccActionTwo; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.List; + +/** + * The type Tcc transaction service. + * + * @author zhangsen + */ +public class TccTransactionService { + + private TccActionOne tccActionOne; + + private TccActionTwo tccActionTwo; + + /** + * 发起分布式事务 + * + * @return string string + */ + @GlobalTransactional + public String doTransactionCommit() { + //第一个TCC 事务参与者 + boolean result = tccActionOne.prepare(null, 1); + if (!result) { + throw new RuntimeException("TccActionOne failed."); + } + List list = new ArrayList<>(); + list.add("c1"); + list.add("c2"); + result = tccActionTwo.prepare(null, "two", list); + if (!result) { + throw new RuntimeException("TccActionTwo failed."); + } + return RootContext.getXID(); + } + + public void checkBranchTransaction(String xid, boolean commit) { + String actionOneResult = ResultHolder.getActionOneResult(xid); + String actionTwoResult = ResultHolder.getActionTwoResult(xid); + Assert.isTrue(commit ? "T".equals(actionOneResult) : "F".equals(actionOneResult), "分支事务" + (commit ? "提交" : "回滚") + "失败"); + Assert.isTrue(commit ? "T".equals(actionTwoResult) : "F".equals(actionTwoResult), "分支事务" + (commit ? "提交" : "回滚") + "失败"); + } + + /** + * Do transaction rollback string. + */ + @GlobalTransactional + public void doTransactionRollback() { + //第一个TCC 事务参与者 + boolean result = tccActionOne.prepare(null, 1); + if (!result) { + throw new RuntimeException("TccActionOne failed."); + } + List list = new ArrayList<>(); + list.add("c1"); + list.add("c2"); + result = tccActionTwo.prepare(null, "two", list); + if (!result) { + throw new RuntimeException("TccActionTwo failed."); + } + + throw new RuntimeException("transaction rollback"); + } + + /** + * Sets tcc action one. + * + * @param tccActionOne the tcc action one + */ + public void setTccActionOne(TccActionOne tccActionOne) { + this.tccActionOne = tccActionOne; + } + + /** + * Sets tcc action two. + * + * @param tccActionTwo the tcc action two + */ + public void setTccActionTwo(TccActionTwo tccActionTwo) { + this.tccActionTwo = tccActionTwo; + } +} diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccConsumerStarter.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccConsumerStarter.java new file mode 100644 index 000000000..7f786ceef --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccConsumerStarter.java @@ -0,0 +1,62 @@ +/* + * 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.stater; + +import org.apache.seata.common.util.StringUtils; +import org.apache.seata.service.TccTransactionService; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.util.Assert; + +public class TccConsumerStarter { + private static TccTransactionService tccTransactionService = null; + + public static void main(String[] args) throws Exception { + new TccConsumerStarter().start0(args); + } + + private void start0(String[] args) throws Exception { + ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/seata-dubbo-reference.xml"); + tccTransactionService = (TccTransactionService)applicationContext.getBean("tccTransactionService"); + + //分布式事务提交demo + transactionCommitDemo(); + //分布式事务回滚demo + transactionRollbackDemo(); + } + + private static void transactionCommitDemo() throws InterruptedException { + String txId = tccTransactionService.doTransactionCommit(); + System.out.println(txId); + Assert.isTrue(StringUtils.isNotEmpty(txId), "事务开启失败"); + + System.out.println("transaction commit demo finish."); + } + + private static void transactionRollbackDemo() throws InterruptedException { + try { + tccTransactionService.doTransactionRollback(); + Assert.isTrue(false, "分布式事务未回滚"); + } catch (Throwable t) { + Assert.isTrue(true, "分布式事务异常回滚"); + } + + //wait rollback + Thread.sleep(3000); + + System.out.println("transaction rollback demo finish."); + } +} diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccProviderStarter.java b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccProviderStarter.java new file mode 100644 index 000000000..b1c9631fa --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/java/org/apache/seata/stater/TccProviderStarter.java @@ -0,0 +1,56 @@ +/* + * 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.stater; + +import org.apache.curator.test.TestingServer; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.io.IOException; + +public class TccProviderStarter { + + private static TestingServer server; + + public static void main(String[] args) throws Exception { + new TccProviderStarter().start0(args); + } + + protected void start0(String[] args) throws Exception { + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + if (server != null) { + try { + server.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + })); + + //mock zk server + mockZKServer(); + + new ClassPathXmlApplicationContext( "spring/seata-dubbo-provider.xml"); + //keep run + Thread.currentThread().join(); + } + + private static void mockZKServer() throws Exception { + //Mock zk server,作为 transfer 配置中心 + server = new TestingServer(2181, true); + server.start(); + } +} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/file.conf b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/file.conf similarity index 100% rename from saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/file.conf rename to saga-sample/spring-dubbo-seata-tcc/src/main/resources/file.conf diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/logback.xml b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/logback.xml similarity index 100% rename from saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/logback.xml rename to saga-sample/spring-dubbo-seata-tcc/src/main/resources/logback.xml diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/registry.conf b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/registry.conf similarity index 100% rename from saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/registry.conf rename to saga-sample/spring-dubbo-seata-tcc/src/main/resources/registry.conf diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-provider.xml b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-provider.xml new file mode 100644 index 000000000..e1ee0eddb --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-provider.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-reference.xml b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-reference.xml new file mode 100644 index 000000000..f198d18ee --- /dev/null +++ b/saga-sample/spring-dubbo-seata-tcc/src/main/resources/spring/seata-dubbo-reference.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/e2e-files/commit.yaml b/saga-sample/spring-seata-dubbo-saga/e2e-files/commit.yaml deleted file mode 100644 index 5aed33a4e..000000000 --- a/saga-sample/spring-seata-dubbo-saga/e2e-files/commit.yaml +++ /dev/null @@ -1 +0,0 @@ -{"res": "commit"} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/e2e-files/rollback.yaml b/saga-sample/spring-seata-dubbo-saga/e2e-files/rollback.yaml deleted file mode 100644 index 635f7b83a..000000000 --- a/saga-sample/spring-seata-dubbo-saga/e2e-files/rollback.yaml +++ /dev/null @@ -1 +0,0 @@ -{"res": "rollback"} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/e2e-replace/file.conf b/saga-sample/spring-seata-dubbo-saga/e2e-replace/file.conf deleted file mode 100644 index cf8230524..000000000 --- a/saga-sample/spring-seata-dubbo-saga/e2e-replace/file.conf +++ /dev/null @@ -1,126 +0,0 @@ -# -# 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. -# - -transport { - # tcp, unix-domain-socket - type = "TCP" - #NIO, NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the tm client batch send request enable - enableTmClientBatchSendRequest = false - # the rm client batch send request enable - enableRmClientBatchSendRequest = true - # the rm client rpc request timeout - rpcRmRequestTimeout = 2000 - # the tm client rpc request timeout - rpcTmRequestTimeout = 30000 - # the rm client rpc request timeout - rpcRmRequestTimeout = 15000 - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "seata:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - tableMetaCheckerInterval = 60000 - reportSuccessEnable = false - sagaBranchRegisterEnable = false - sagaJsonParser = "fastjson" - sagaRetryPersistModeUpdate = false - sagaCompensatePersistModeUpdate = false - tccActionInterceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000 - sqlParserType = "druid" - branchExecutionTimeoutXA = 60000 - connectionTwoPhaseHoldTimeoutXA = 10000 - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - defaultGlobalTransactionTimeout = 60000 - degradeCheck = false - degradeCheckPeriod = 2000 - degradeCheckAllowTimes = 10 - interceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000 - } - undo { - dataValidation = true - onlyCareUpdateColumns = true - logSerialization = "jackson" - logTable = "undo_log" - compress { - enable = true - # allow zip, gzip, deflater, lz4, bzip2, zstd default is zip - type = zip - # if rollback info size > threshold, then will be compress - # allow k m g t - threshold = 64k - } - } - loadBalance { - type = "XID" - virtualNodes = 10 - } -} -log { - exceptionRate = 100 -} -tcc { - fence { - # tcc fence log table name - logTableName = tcc_fence_log - # tcc fence log clean period - cleanPeriod = 1h - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/pom.xml b/saga-sample/spring-seata-dubbo-saga/pom.xml deleted file mode 100644 index a31895d70..000000000 --- a/saga-sample/spring-seata-dubbo-saga/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - 4.0.0 - - org.apache.seata - spring-seata-dubbo-saga - 2.1.0 - pom - - - spring-seata-dubbo-saga-consumer - spring-seata-dubbo-saga-provider - spring-seata-dubbo-saga-common - - - - UTF-8 - UTF-8 - 1.8 - 1.8 - - - - \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/seata-e2e.yaml b/saga-sample/spring-seata-dubbo-saga/seata-e2e.yaml deleted file mode 100644 index bd403e256..000000000 --- a/saga-sample/spring-seata-dubbo-saga/seata-e2e.yaml +++ /dev/null @@ -1,80 +0,0 @@ -e2e: - scene_name: saga-spring-seata-dubbo-saga - # retry config - retry: - max: 5 - interval: 15s - total_timeout: 20m - # services in docker-compose - modules: - # consume services - consumers: - # docker service name - - name: spring-seata-dubbo-saga-consumer # this name should be the same as module name, it is indicated to be builded as an image - # service params in a service of docker-compose service - docker_service: - hostname: spring-seata-dubbo-saga-consumer - restart: always - container_name: test - depends_on: - seata-server: - condition: service_started - spring-seata-dubbo-saga-provider: - condition: service_started - environment: - seata.address: seata - zookeeper.address: zookeeper - E2E_ENV: open - # provider service - providers: - - name: spring-seata-dubbo-saga-provider - docker_service: - hostname: spring-seata-dubbo-saga-provider - restart: on-failure - depends_on: - seata-server: - condition: service_started - zookeeper: - condition: service_healthy - environment: - seata.address: seata - zookeeper.address: zookeeper - E2E_ENV: open - # infrastructure services - infrastructures: - - name: seata-server - docker_service: - hostname: seata - image: apache/seata-server:2.1.0 -# ports: -# - "7091:7091" -# - "8091:8091" - environment: - SEATA_PORT: 8091 - STORE_MODE: file - - name: zookeeper - docker_service: - hostname: zookeeper - image: zookeeper:3.8.4 - # ports: - # - "2181:2181" - healthcheck: - test: '[ "CMD", "echo", "ruok", "|", "nc", "localhost", "2181", "|", "grep", "imok" ]' - interval: 30s - timeout: 10s - retries: 3 - - replace: - - source: e2e-replace/file.conf - dest: spring-seata-dubbo-saga-consumer/src/main/resources/file.conf - - source: e2e-replace/file.conf - dest: spring-seata-dubbo-saga-provider/src/main/resources/file.conf - - # cases to verify - cases: - - name: normal test rollback - invoke: 'docker exec test cat rollback.yaml' - verify: './e2e-files/rollback.yaml' - - name: normal test commit - invoke: 'docker exec test cat commit.yaml' - verify: './e2e-files/commit.yaml' \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/pom.xml b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/pom.xml deleted file mode 100644 index c4ee84362..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - org.apache.seata - spring-seata-dubbo-saga - 2.1.0 - - - spring-seata-dubbo-saga-common - 2.1.0 - spring-seata-dubbo-tcc-common - spring-seata-dubbo-tcc-common - - - UTF-8 - - - - - - org.slf4j - slf4j-api - 1.7.32 - - - - ch.qos.logback - logback-classic - 1.2.13 - - - - org.slf4j - jcl-over-slf4j - 1.7.32 - - - org.slf4j - log4j-over-slf4j - 1.7.32 - - - - diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/src/main/java/seata/e2e/E2EUtil.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/src/main/java/seata/e2e/E2EUtil.java deleted file mode 100644 index 3b6b03c62..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-common/src/main/java/seata/e2e/E2EUtil.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apache.seata.e2e; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Map; - -public class E2EUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(E2EUtil.class); - private E2EUtil() { - } - public static void writeE2EResFile(String outPutRes, String name) { - try { - Files.write(Paths.get(name), outPutRes.getBytes()); - } catch (IOException e) { - LOGGER.error("write E2EResFile error", e); - } - } - - public static boolean isInE2ETest() { - Map envs = System.getenv(); - String env = envs.getOrDefault("E2E_ENV", ""); - return "open".equals(env); - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/pom.xml b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/pom.xml deleted file mode 100644 index 50ea84aff..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/pom.xml +++ /dev/null @@ -1,140 +0,0 @@ - - 4.0.0 - - org.apache.seata - spring-seata-dubbo-saga - 2.1.0 - - - spring-seata-dubbo-saga-consumer - 2.1.0 - spring-seata-dubbo-tcc-consumer - spring-seata-dubbo-tcc-consumer - - - UTF-8 - - - - - - org.slf4j - slf4j-api - 1.7.32 - - - - ch.qos.logback - logback-classic - 1.2.13 - - - - org.slf4j - jcl-over-slf4j - 1.7.32 - - - org.slf4j - log4j-over-slf4j - 1.7.32 - - - - - org.apache.seata - seata-all - 2.1.0 - - - - org.springframework - spring-jdbc - 5.3.20 - - - - com.fasterxml.jackson.core - jackson-databind - 2.13.5 - - - - - com.h2database - h2 - 2.2.220 - - - - org.apache.dubbo - dubbo - 3.1.11 - - - - org.apache.dubbo - dubbo-remoting-zookeeper-curator5 - 3.1.2 - - - org.apache.curator - curator-x-discovery - 5.1.0 - - - org.apache.curator - curator-test - 5.1.0 - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - - - org.apache.seata - spring-seata-dubbo-saga-common - 2.1.0 - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - - - org.apache.seata.consumer.SagaTransactionStarter - - - META-INF/spring.handlers - - - META-INF/spring.schemas - - - - - - - - - diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/SagaTransactionStarter.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/SagaTransactionStarter.java deleted file mode 100644 index c7ee020fe..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/SagaTransactionStarter.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.consumer; - -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.seata.saga.engine.AsyncCallback; -import org.apache.seata.saga.engine.StateMachineEngine; -import org.apache.seata.saga.proctrl.ProcessContext; -import org.apache.seata.saga.statelang.domain.ExecutionStatus; -import org.apache.seata.saga.statelang.domain.StateMachineInstance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.util.Assert; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; - -import static org.apache.seata.e2e.E2EUtil.isInE2ETest; -import static org.apache.seata.e2e.E2EUtil.writeE2EResFile; - -@EnableDubbo(scanBasePackages = {"org.apache.seata.consumer"}) -@ComponentScan(basePackages = {"org.apache.seata.consumer"}) -public class SagaTransactionStarter { - - private static final Logger LOGGER = LoggerFactory.getLogger(SagaTransactionStarter.class); - - public static void main(String[] args) throws InterruptedException { - if (isInE2ETest()) { - // wait provider - Thread.sleep(5000); - } - - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SagaTransactionStarter.class); - - StateMachineEngine stateMachineEngine = (StateMachineEngine) applicationContext.getBean("stateMachineEngine"); - - transactionCommittedDemo(stateMachineEngine); - - transactionCompensatedDemo(stateMachineEngine); - } - - private static void transactionCommittedDemo(StateMachineEngine stateMachineEngine) { - - Map startParams = new HashMap<>(3); - String businessKey = String.valueOf(System.currentTimeMillis()); - startParams.put("businessKey", businessKey); - startParams.put("count", 10); - startParams.put("amount", new BigDecimal("100")); - - //sync test - StateMachineInstance inst = stateMachineEngine.startWithBusinessKey("reduceInventoryAndBalance", null, - businessKey, startParams); - - Assert.isTrue(ExecutionStatus.SU.equals(inst.getStatus()), - "saga transaction execute failed. XID: " + inst.getId()); - LOGGER.info("saga transaction commit succeed. XID: " + inst.getId()); - - inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstanceByBusinessKey( - businessKey, null); - Assert.isTrue(ExecutionStatus.SU.equals(inst.getStatus()), - "saga transaction execute failed. XID: " + inst.getId()); - - //async test - businessKey = String.valueOf(System.currentTimeMillis()); - inst = stateMachineEngine.startWithBusinessKeyAsync("reduceInventoryAndBalance", null, businessKey, startParams, - CALL_BACK); - - waitingForFinish(inst); - - Assert.isTrue(ExecutionStatus.SU.equals(inst.getStatus()), - "saga transaction execute failed. XID: " + inst.getId()); - if (isInE2ETest()) { - String res = "{\"res\": \"commit\"}"; - writeE2EResFile(res, "commit.yaml"); - } - LOGGER.info("saga transaction commit succeed. XID: " + inst.getId()); - } - - private static void transactionCompensatedDemo(StateMachineEngine stateMachineEngine) { - Map startParams = new HashMap<>(4); - String businessKey = String.valueOf(System.currentTimeMillis()); - startParams.put("businessKey", businessKey); - startParams.put("count", 10); - startParams.put("amount", new BigDecimal("100")); - startParams.put("mockReduceBalanceFail", "true"); - - //sync test - StateMachineInstance inst = stateMachineEngine.startWithBusinessKey("reduceInventoryAndBalance", null, - businessKey, startParams); - - //async test - businessKey = String.valueOf(System.currentTimeMillis()); - inst = stateMachineEngine.startWithBusinessKeyAsync("reduceInventoryAndBalance", null, businessKey, startParams, - CALL_BACK); - - waitingForFinish(inst); - - Assert.isTrue(ExecutionStatus.SU.equals(inst.getCompensationStatus()), - "saga transaction compensate failed. XID: " + inst.getId()); - if (isInE2ETest()) { - String res = "{\"res\": \"rollback\"}"; - writeE2EResFile(res, "rollback.yaml"); - } - LOGGER.info("saga transaction compensate succeed. XID: " + inst.getId()); - } - - private static final Object LOCK = new Object(); - - private static final AsyncCallback CALL_BACK = new AsyncCallback() { - @Override - public void onFinished(ProcessContext context, StateMachineInstance stateMachineInstance) { - synchronized (LOCK) { - LOCK.notifyAll(); - } - } - - @Override - public void onError(ProcessContext context, StateMachineInstance stateMachineInstance, Exception exp) { - synchronized (LOCK) { - LOCK.notifyAll(); - } - } - }; - - private static void waitingForFinish(StateMachineInstance inst) { - synchronized (LOCK) { - if (ExecutionStatus.RU.equals(inst.getStatus())) { - try { - LOCK.wait(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - LOGGER.error("Thread was interrupted", e); - } - } - } - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DataSourceConfiguration.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DataSourceConfiguration.java deleted file mode 100644 index cf1456d95..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DataSourceConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.consumer.config; - -import org.h2.jdbcx.JdbcConnectionPool; -import org.h2.jdbcx.JdbcDataSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; -import org.springframework.jdbc.datasource.init.DataSourceInitializer; -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; - -import javax.sql.DataSource; - -@Configuration -public class DataSourceConfiguration { - - @Bean - public DataSource dataSource() { - JdbcDataSource jdbcDataSource = new JdbcDataSource(); - jdbcDataSource.setUser("sa"); - jdbcDataSource.setPassword("sa"); - jdbcDataSource.setUrl("jdbc:h2:mem:seata_saga"); - return JdbcConnectionPool.create(jdbcDataSource); - } - - @Bean - public DataSourceInitializer dataSourceInitializer(DataSource dataSource) { - DataSourceInitializer dataSourceInitializer = new DataSourceInitializer(); - dataSourceInitializer.setDataSource(dataSource); - ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(); - resourceDatabasePopulator.addScript(new ClassPathResource("sql/h2_init.sql")); - dataSourceInitializer.setDatabasePopulator(resourceDatabasePopulator); - return dataSourceInitializer; - } -} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DubboConsumerConfiguration.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DubboConsumerConfiguration.java deleted file mode 100644 index ddd2e98f2..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/DubboConsumerConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.consumer.config; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.seata.provider.action.BalanceAction; -import org.apache.seata.provider.action.InventoryAction; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static org.apache.seata.e2e.E2EUtil.isInE2ETest; - -/** - * @author wangte - * Create At 2024/1/20 - */ -@Configuration -public class DubboConsumerConfiguration { - - public static final String CONSUMER_APP_NAME = "seata-saga-consumer"; - - @DubboReference(id = "balanceAction") - private BalanceAction balanceAction; - - @DubboReference(id = "inventoryAction") - private InventoryAction inventoryAction; - - @Bean - public ApplicationConfig applicationConfig() { - ApplicationConfig applicationConfig = new ApplicationConfig(CONSUMER_APP_NAME); - applicationConfig.setQosEnable(false); - return applicationConfig; - } - - @Bean - public RegistryConfig registryConfig() { - RegistryConfig registryConfig = new RegistryConfig(); - if (isInE2ETest()) { - registryConfig.setAddress("zookeeper://zookeeper:2181"); - } else { - registryConfig.setAddress("zookeeper://localhost:2181"); - } - return registryConfig; - } - - @Bean - public ProtocolConfig protocolConfig() { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.setName("dubbo"); - protocolConfig.setPort(20882); - return protocolConfig; - } - -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/SagaConfiguration.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/SagaConfiguration.java deleted file mode 100644 index 1f174598a..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/consumer/config/SagaConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.seata.consumer.config; - -import org.apache.seata.saga.engine.StateMachineConfig; -import org.apache.seata.saga.engine.StateMachineEngine; -import org.apache.seata.saga.engine.config.DbStateMachineConfig; -import org.apache.seata.saga.engine.impl.ProcessCtrlStateMachineEngine; -import org.apache.seata.saga.rm.StateMachineEngineHolder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.sql.DataSource; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * @author wangte - * Create At 2024/1/20 - */ -@Configuration -public class SagaConfiguration { - - @Bean - public StateMachineConfig stateMachineConfig(DataSource dataSource) { - DbStateMachineConfig dbStateMachineConfig = new DbStateMachineConfig(); - dbStateMachineConfig.setApplicationId("seata-saga-consumer"); - dbStateMachineConfig.setDataSource(dataSource); - dbStateMachineConfig.setEnableAsync(true); - dbStateMachineConfig.setResources(new String[]{"classpath*:statelang/*.json"}); - dbStateMachineConfig.setTxServiceGroup("my_test_tx_group"); - dbStateMachineConfig.setThreadPoolExecutor(new ThreadPoolExecutor(1, 20, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100))); - return dbStateMachineConfig; - } - - @Bean - public StateMachineEngine stateMachineEngine(StateMachineConfig stateMachineConfig) { - ProcessCtrlStateMachineEngine processCtrlStateMachineEngine = new ProcessCtrlStateMachineEngine(); - processCtrlStateMachineEngine.setStateMachineConfig(stateMachineConfig); - return processCtrlStateMachineEngine; - } - - @Bean - public StateMachineEngineHolder stateMachineEngineHolder(StateMachineEngine stateMachineEngine) { - StateMachineEngineHolder stateMachineEngineHolder = new StateMachineEngineHolder(); - stateMachineEngineHolder.setStateMachineEngine(stateMachineEngine); - return stateMachineEngineHolder; - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/InventoryAction.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/InventoryAction.java deleted file mode 100644 index 33a0cc98e..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/InventoryAction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.provider.action; - -/** - * Inventory Actions - */ -public interface InventoryAction { - - /** - * reduce - * - * @param count - * @return - */ - boolean reduce(String businessKey, int count); - - /** - * increase - * - * @return - */ - boolean compensateReduce(String businessKey); -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java deleted file mode 100644 index 5b2ed26e9..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.provider.action.impl; - -import org.apache.dubbo.config.annotation.DubboService; -import org.apache.seata.provider.action.BalanceAction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigDecimal; -import java.util.Map; - -/** - * @author lorne.cl - */ -@DubboService -public class BalanceActionImpl implements BalanceAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(BalanceActionImpl.class); - - @Override - public boolean reduce(String businessKey, BigDecimal amount, Map params) { - if(params != null) { - Object throwException = params.get("throwException"); - if (throwException != null && "true".equals(throwException.toString())) { - throw new RuntimeException("reduce balance failed"); - } - } - LOGGER.info("reduce balance succeed, amount: " + amount + ", businessKey:" + businessKey); - return true; - } - - @Override - public boolean compensateReduce(String businessKey, Map params) { - if(params != null) { - Object throwException = params.get("throwException"); - if (throwException != null && "true".equals(throwException.toString())) { - throw new RuntimeException("compensate reduce balance failed"); - } - } - LOGGER.info("compensate reduce balance succeed, businessKey:" + businessKey); - return true; - } -} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java deleted file mode 100644 index 7d00c3045..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.provider.action.impl; - -import org.apache.dubbo.config.annotation.DubboService; -import org.apache.seata.provider.action.InventoryAction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author lorne.cl - */ -@DubboService -public class InventoryActionImpl implements InventoryAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(InventoryActionImpl.class); - - @Override - public boolean reduce(String businessKey, int count) { - LOGGER.info("reduce inventory succeed, count: " + count + ", businessKey:" + businessKey); - return true; - } - - @Override - public boolean compensateReduce(String businessKey) { - LOGGER.info("compensate reduce inventory succeed, businessKey:" + businessKey); - return true; - } -} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/sql/h2_init.sql b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/sql/h2_init.sql deleted file mode 100644 index d26f42edb..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/sql/h2_init.sql +++ /dev/null @@ -1,74 +0,0 @@ --- --- 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. --- - -CREATE CACHED TABLE "PUBLIC"."SEATA_STATE_INST"( - "ID" VARCHAR NOT NULL COMMENT 'id', - "MACHINE_INST_ID" VARCHAR NOT NULL COMMENT 'state machine instance id', - "NAME" VARCHAR NOT NULL COMMENT 'state name', - "TYPE" VARCHAR COMMENT 'state type', - "SERVICE_NAME" VARCHAR COMMENT 'service name', - "SERVICE_METHOD" VARCHAR COMMENT 'method name', - "SERVICE_TYPE" VARCHAR COMMENT 'service type', - "BUSINESS_KEY" VARCHAR COMMENT 'business key', - "STATE_ID_COMPENSATED_FOR" VARCHAR COMMENT 'state compensated for', - "STATE_ID_RETRIED_FOR" VARCHAR COMMENT 'state retried for', - "GMT_STARTED" TIMESTAMP NOT NULL COMMENT 'start time', - "IS_FOR_UPDATE" TINYINT COMMENT 'is service for update', - "INPUT_PARAMS" CLOB COMMENT 'input parameters', - "OUTPUT_PARAMS" CLOB COMMENT 'output parameters', - "STATUS" VARCHAR NOT NULL COMMENT 'status(SU succeed|FA failed|UN unknown|SK skipped|RU running)', - "EXCEP" BLOB COMMENT 'exception', - "GMT_UPDATED" TIMESTAMP COMMENT 'update time', - "GMT_END" TIMESTAMP COMMENT 'end time' -); - - --- PUBLIC.SEATA_STATE_MACHINE_DEF definition - -CREATE CACHED TABLE "PUBLIC"."SEATA_STATE_MACHINE_DEF"( - "ID" VARCHAR NOT NULL COMMENT 'id', - "NAME" VARCHAR NOT NULL COMMENT 'name', - "TENANT_ID" VARCHAR NOT NULL COMMENT 'tenant id', - "APP_NAME" VARCHAR NOT NULL COMMENT 'application name', - "TYPE" VARCHAR COMMENT 'state language type', - "COMMENT_" VARCHAR COMMENT 'comment', - "VER" VARCHAR NOT NULL COMMENT 'version', - "GMT_CREATE" TIMESTAMP NOT NULL COMMENT 'create time', - "STATUS" VARCHAR NOT NULL COMMENT 'status(AC:active|IN:inactive)', - "CONTENT" CLOB COMMENT 'content', - "RECOVER_STRATEGY" VARCHAR COMMENT 'transaction recover strategy(compensate|retry)' -); - - --- PUBLIC.SEATA_STATE_MACHINE_INST definition - -CREATE CACHED TABLE "PUBLIC"."SEATA_STATE_MACHINE_INST"( - "ID" VARCHAR NOT NULL COMMENT 'id', - "MACHINE_ID" VARCHAR NOT NULL COMMENT 'state machine definition id', - "TENANT_ID" VARCHAR NOT NULL COMMENT 'tenant id', - "PARENT_ID" VARCHAR COMMENT 'parent id', - "GMT_STARTED" TIMESTAMP NOT NULL COMMENT 'start time', - "BUSINESS_KEY" VARCHAR COMMENT 'business key', - "START_PARAMS" CLOB COMMENT 'start parameters', - "GMT_END" TIMESTAMP COMMENT 'end time', - "EXCEP" BLOB COMMENT 'exception', - "END_PARAMS" CLOB COMMENT 'end parameters', - "STATUS" VARCHAR COMMENT 'status(SU succeed|FA failed|UN unknown|SK skipped|RU running)', - "COMPENSATION_STATUS" VARCHAR COMMENT 'compensation status(SU succeed|FA failed|UN unknown|SK skipped|RU running)', - "IS_RUNNING" TINYINT COMMENT 'is running(0 no|1 yes)', - "GMT_UPDATED" TIMESTAMP NOT NULL -); \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/statelang/reduce_inventory_and_balance.json b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/statelang/reduce_inventory_and_balance.json deleted file mode 100644 index 4d5969fde..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-consumer/src/main/resources/statelang/reduce_inventory_and_balance.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "Name": "reduceInventoryAndBalance", - "Comment": "reduce inventory then reduce balance in a transaction", - "StartState": "ReduceInventory", - "Version": "0.0.1", - "States": { - "ReduceInventory": { - "Type": "ServiceTask", - "ServiceName": "inventoryAction", - "ServiceMethod": "reduce", - "CompensateState": "CompensateReduceInventory", - "Next": "ChoiceState", - "Input": [ - "$.[businessKey]", - "$.[count]" - ], - "Output": { - "reduceInventoryResult": "$.#root" - }, - "Status": { - "#root == true": "SU", - "#root == false": "FA", - "$Exception{java.lang.Throwable}": "UN" - } - }, - "ChoiceState": { - "Type": "Choice", - "Choices": [ - { - "Expression": "[reduceInventoryResult] == true", - "Next": "ReduceBalance" - } - ], - "Default": "Fail" - }, - "ReduceBalance": { - "Type": "ServiceTask", - "ServiceName": "balanceAction", - "ServiceMethod": "reduce", - "CompensateState": "CompensateReduceBalance", - "Input": [ - "$.[businessKey]", - "$.[amount]", - { - "throwException": "$.[mockReduceBalanceFail]" - } - ], - "Output": { - "compensateReduceBalanceResult": "$.#root" - }, - "Status": { - "#root == true": "SU", - "#root == false": "FA", - "$Exception{java.lang.Throwable}": "UN" - }, - "Catch": [ - { - "Exceptions": [ - "java.lang.Throwable" - ], - "Next": "CompensationTrigger" - } - ], - "Next": "Succeed" - }, - "CompensateReduceInventory": { - "Type": "ServiceTask", - "ServiceName": "inventoryAction", - "ServiceMethod": "compensateReduce", - "Input": [ - "$.[businessKey]" - ] - }, - "CompensateReduceBalance": { - "Type": "ServiceTask", - "ServiceName": "balanceAction", - "ServiceMethod": "compensateReduce", - "Input": [ - "$.[businessKey]" - ] - }, - "CompensationTrigger": { - "Type": "CompensationTrigger", - "Next": "Fail" - }, - "Succeed": { - "Type": "Succeed" - }, - "Fail": { - "Type": "Fail", - "ErrorCode": "PURCHASE_FAILED", - "Message": "purchase failed" - } - } -} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/pom.xml b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/pom.xml deleted file mode 100644 index a9fd5d920..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/pom.xml +++ /dev/null @@ -1,140 +0,0 @@ - - 4.0.0 - - org.apache.seata - spring-seata-dubbo-saga - 2.1.0 - - - spring-seata-dubbo-saga-provider - 2.1.0 - spring-seata-dubbo-tcc-provider - spring-seata-dubbo-tcc-provider - - - UTF-8 - - - - - - org.slf4j - slf4j-api - 1.7.32 - - - - ch.qos.logback - logback-classic - 1.2.13 - - - - org.slf4j - jcl-over-slf4j - 1.7.32 - - - org.slf4j - log4j-over-slf4j - 1.7.32 - - - - - org.apache.seata - seata-all - 2.1.0 - - - - org.springframework - spring-jdbc - 5.3.20 - - - - com.fasterxml.jackson.core - jackson-databind - 2.13.5 - - - - - com.h2database - h2 - 2.2.220 - - - - org.apache.dubbo - dubbo - 3.1.11 - - - - org.apache.dubbo - dubbo-remoting-zookeeper-curator5 - 3.1.2 - - - org.apache.curator - curator-x-discovery - 5.1.0 - - - org.apache.curator - curator-test - 5.1.0 - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - - - org.apache.seata - spring-seata-dubbo-saga-common - 2.1.0 - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - - - org.apache.seata.provider.DubboProviderStarter - - - META-INF/spring.handlers - - - META-INF/spring.schemas - - - - - - - - - diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/DubboProviderStarter.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/DubboProviderStarter.java deleted file mode 100644 index 307cab83f..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/DubboProviderStarter.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.provider; - -import org.apache.curator.test.TestingServer; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.ComponentScan; - -import static org.apache.seata.e2e.E2EUtil.isInE2ETest; - -/** - * @author wangte - * Create At 2024/1/20 - */ -@EnableDubbo(scanBasePackages = {"org.apache.seata.provider"}) -@ComponentScan(basePackages = {"org.apache.seata.provider"}) -public class DubboProviderStarter { - - private static final Logger LOGGER = LoggerFactory.getLogger(DubboProviderStarter.class); - - private static TestingServer server; - - public static void main(String[] args) throws Exception { -// Runtime.getRuntime().addShutdownHook(new Thread(() -> { -// if (server != null) { -// try { -// server.close(); -// } catch (IOException e) { -// throw new RuntimeException(e); -// } -// } -// })); - -// mockZKServer(); - if (isInE2ETest()) { - // wait seata-server - Thread.sleep(2000); - } - - new AnnotationConfigApplicationContext(DubboProviderStarter.class); - - LOGGER.info("dubbo provider started"); - //keep run - Thread.currentThread().join(); - } - - private static void mockZKServer() throws Exception { - server = new TestingServer(2181, true); - server.start(); - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/BalanceAction.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/BalanceAction.java deleted file mode 100644 index cb337b29a..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/BalanceAction.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.provider.action; - -import java.math.BigDecimal; -import java.util.Map; - -/** - * Balance Actions - */ -public interface BalanceAction { - - /** - * reduce - * - * @param businessKey - * @param amount - * @param params - * @return - */ - boolean reduce(String businessKey, BigDecimal amount, Map params); - - /** - * compensateReduce - * - * @param businessKey - * @param params - * @return - */ - boolean compensateReduce(String businessKey, Map params); - -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/InventoryAction.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/InventoryAction.java deleted file mode 100644 index 33a0cc98e..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/InventoryAction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.provider.action; - -/** - * Inventory Actions - */ -public interface InventoryAction { - - /** - * reduce - * - * @param count - * @return - */ - boolean reduce(String businessKey, int count); - - /** - * increase - * - * @return - */ - boolean compensateReduce(String businessKey); -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java deleted file mode 100644 index 5b2ed26e9..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/BalanceActionImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.provider.action.impl; - -import org.apache.dubbo.config.annotation.DubboService; -import org.apache.seata.provider.action.BalanceAction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigDecimal; -import java.util.Map; - -/** - * @author lorne.cl - */ -@DubboService -public class BalanceActionImpl implements BalanceAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(BalanceActionImpl.class); - - @Override - public boolean reduce(String businessKey, BigDecimal amount, Map params) { - if(params != null) { - Object throwException = params.get("throwException"); - if (throwException != null && "true".equals(throwException.toString())) { - throw new RuntimeException("reduce balance failed"); - } - } - LOGGER.info("reduce balance succeed, amount: " + amount + ", businessKey:" + businessKey); - return true; - } - - @Override - public boolean compensateReduce(String businessKey, Map params) { - if(params != null) { - Object throwException = params.get("throwException"); - if (throwException != null && "true".equals(throwException.toString())) { - throw new RuntimeException("compensate reduce balance failed"); - } - } - LOGGER.info("compensate reduce balance succeed, businessKey:" + businessKey); - return true; - } -} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java deleted file mode 100644 index 7d00c3045..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/action/impl/InventoryActionImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.provider.action.impl; - -import org.apache.dubbo.config.annotation.DubboService; -import org.apache.seata.provider.action.InventoryAction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author lorne.cl - */ -@DubboService -public class InventoryActionImpl implements InventoryAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(InventoryActionImpl.class); - - @Override - public boolean reduce(String businessKey, int count) { - LOGGER.info("reduce inventory succeed, count: " + count + ", businessKey:" + businessKey); - return true; - } - - @Override - public boolean compensateReduce(String businessKey) { - LOGGER.info("compensate reduce inventory succeed, businessKey:" + businessKey); - return true; - } -} \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/config/DubboProviderConfiguration.java b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/config/DubboProviderConfiguration.java deleted file mode 100644 index c23770c73..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/java/org/apache/seata/provider/config/DubboProviderConfiguration.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.provider.config; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static org.apache.seata.e2e.E2EUtil.isInE2ETest; - -/** - * @author wangte - * Create At 2024/1/20 - */ -@Configuration -public class DubboProviderConfiguration { - - public static final String PROVIDER_APP_NAME = "seata-saga-provider"; - - @Bean - public ApplicationConfig applicationConfig() { - ApplicationConfig applicationConfig = new ApplicationConfig(PROVIDER_APP_NAME); - applicationConfig.setQosEnable(false); - return applicationConfig; - } - - @Bean - public RegistryConfig registryConfig() { - RegistryConfig registryConfig = new RegistryConfig(); - if (isInE2ETest()) { - registryConfig.setAddress("zookeeper://zookeeper:2181"); - } else { - registryConfig.setAddress("zookeeper://localhost:2181"); - } - return registryConfig; - } - - @Bean - public ProtocolConfig protocolConfig() { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.setName("dubbo"); - protocolConfig.setPort(20881); - return protocolConfig; - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/file.conf b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/file.conf deleted file mode 100644 index e426f6661..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/file.conf +++ /dev/null @@ -1,126 +0,0 @@ -# -# 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. -# - -transport { - # tcp, unix-domain-socket - type = "TCP" - #NIO, NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the tm client batch send request enable - enableTmClientBatchSendRequest = false - # the rm client batch send request enable - enableRmClientBatchSendRequest = true - # the rm client rpc request timeout - rpcRmRequestTimeout = 2000 - # the tm client rpc request timeout - rpcTmRequestTimeout = 30000 - # the rm client rpc request timeout - rpcRmRequestTimeout = 15000 - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - tableMetaCheckerInterval = 60000 - reportSuccessEnable = false - sagaBranchRegisterEnable = false - sagaJsonParser = "fastjson" - sagaRetryPersistModeUpdate = false - sagaCompensatePersistModeUpdate = false - tccActionInterceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000 - sqlParserType = "druid" - branchExecutionTimeoutXA = 60000 - connectionTwoPhaseHoldTimeoutXA = 10000 - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - defaultGlobalTransactionTimeout = 60000 - degradeCheck = false - degradeCheckPeriod = 2000 - degradeCheckAllowTimes = 10 - interceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000 - } - undo { - dataValidation = true - onlyCareUpdateColumns = true - logSerialization = "jackson" - logTable = "undo_log" - compress { - enable = true - # allow zip, gzip, deflater, lz4, bzip2, zstd default is zip - type = zip - # if rollback info size > threshold, then will be compress - # allow k m g t - threshold = 64k - } - } - loadBalance { - type = "XID" - virtualNodes = 10 - } -} -log { - exceptionRate = 100 -} -tcc { - fence { - # tcc fence log table name - logTableName = tcc_fence_log - # tcc fence log clean period - cleanPeriod = 1h - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/logback.xml b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/logback.xml deleted file mode 100644 index 14ecfc137..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/registry.conf b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/registry.conf deleted file mode 100644 index a105dc3e8..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/registry.conf +++ /dev/null @@ -1,124 +0,0 @@ -# -# 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. -# - -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa、custom - type = "file" - - nacos { - application = "seata-server" - serverAddr = "127.0.0.1:8848" - group = "SEATA_GROUP" - namespace = "" - username = "" - password = "" - contextPath = "" - ##if use MSE Nacos with auth, mutex with username/password attribute - #accessKey = "" - #secretKey = "" - ##if use Nacos naming meta-data for SLB service registry, specify nacos address pattern rules here - #slbPattern = "" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - timeout = "0" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - aclToken = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } - custom { - name = "" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig、custom - type = "file" - raft { - metadata-max-age-ms = 30000 - serverAddr = "127.0.0.1:8848" - } - nacos { - serverAddr = "127.0.0.1:8848" - namespace = "" - group = "SEATA_GROUP" - username = "" - password = "" - contextPath = "" - ##if use MSE Nacos with auth, mutex with username/password attribute - #accessKey = "" - #secretKey = "" - dataId = "seata.properties" - } - consul { - serverAddr = "127.0.0.1:8500" - key = "seata.properties" - aclToken = "" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - apolloAccesskeySecret = "" - cluster = "" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - nodePath = "/seata/seata.properties" - } - etcd3 { - serverAddr = "http://localhost:2379" - key = "seata.properties" - } - file { - name = "file.conf" - } - custom { - name = "" - } -} diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/sql/h2_init.sql b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/sql/h2_init.sql deleted file mode 100644 index d26f42edb..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/sql/h2_init.sql +++ /dev/null @@ -1,74 +0,0 @@ --- --- 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. --- - -CREATE CACHED TABLE "PUBLIC"."SEATA_STATE_INST"( - "ID" VARCHAR NOT NULL COMMENT 'id', - "MACHINE_INST_ID" VARCHAR NOT NULL COMMENT 'state machine instance id', - "NAME" VARCHAR NOT NULL COMMENT 'state name', - "TYPE" VARCHAR COMMENT 'state type', - "SERVICE_NAME" VARCHAR COMMENT 'service name', - "SERVICE_METHOD" VARCHAR COMMENT 'method name', - "SERVICE_TYPE" VARCHAR COMMENT 'service type', - "BUSINESS_KEY" VARCHAR COMMENT 'business key', - "STATE_ID_COMPENSATED_FOR" VARCHAR COMMENT 'state compensated for', - "STATE_ID_RETRIED_FOR" VARCHAR COMMENT 'state retried for', - "GMT_STARTED" TIMESTAMP NOT NULL COMMENT 'start time', - "IS_FOR_UPDATE" TINYINT COMMENT 'is service for update', - "INPUT_PARAMS" CLOB COMMENT 'input parameters', - "OUTPUT_PARAMS" CLOB COMMENT 'output parameters', - "STATUS" VARCHAR NOT NULL COMMENT 'status(SU succeed|FA failed|UN unknown|SK skipped|RU running)', - "EXCEP" BLOB COMMENT 'exception', - "GMT_UPDATED" TIMESTAMP COMMENT 'update time', - "GMT_END" TIMESTAMP COMMENT 'end time' -); - - --- PUBLIC.SEATA_STATE_MACHINE_DEF definition - -CREATE CACHED TABLE "PUBLIC"."SEATA_STATE_MACHINE_DEF"( - "ID" VARCHAR NOT NULL COMMENT 'id', - "NAME" VARCHAR NOT NULL COMMENT 'name', - "TENANT_ID" VARCHAR NOT NULL COMMENT 'tenant id', - "APP_NAME" VARCHAR NOT NULL COMMENT 'application name', - "TYPE" VARCHAR COMMENT 'state language type', - "COMMENT_" VARCHAR COMMENT 'comment', - "VER" VARCHAR NOT NULL COMMENT 'version', - "GMT_CREATE" TIMESTAMP NOT NULL COMMENT 'create time', - "STATUS" VARCHAR NOT NULL COMMENT 'status(AC:active|IN:inactive)', - "CONTENT" CLOB COMMENT 'content', - "RECOVER_STRATEGY" VARCHAR COMMENT 'transaction recover strategy(compensate|retry)' -); - - --- PUBLIC.SEATA_STATE_MACHINE_INST definition - -CREATE CACHED TABLE "PUBLIC"."SEATA_STATE_MACHINE_INST"( - "ID" VARCHAR NOT NULL COMMENT 'id', - "MACHINE_ID" VARCHAR NOT NULL COMMENT 'state machine definition id', - "TENANT_ID" VARCHAR NOT NULL COMMENT 'tenant id', - "PARENT_ID" VARCHAR COMMENT 'parent id', - "GMT_STARTED" TIMESTAMP NOT NULL COMMENT 'start time', - "BUSINESS_KEY" VARCHAR COMMENT 'business key', - "START_PARAMS" CLOB COMMENT 'start parameters', - "GMT_END" TIMESTAMP COMMENT 'end time', - "EXCEP" BLOB COMMENT 'exception', - "END_PARAMS" CLOB COMMENT 'end parameters', - "STATUS" VARCHAR COMMENT 'status(SU succeed|FA failed|UN unknown|SK skipped|RU running)', - "COMPENSATION_STATUS" VARCHAR COMMENT 'compensation status(SU succeed|FA failed|UN unknown|SK skipped|RU running)', - "IS_RUNNING" TINYINT COMMENT 'is running(0 no|1 yes)', - "GMT_UPDATED" TIMESTAMP NOT NULL -); \ No newline at end of file diff --git a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/statelang/reduce_inventory_and_balance.json b/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/statelang/reduce_inventory_and_balance.json deleted file mode 100644 index 4d5969fde..000000000 --- a/saga-sample/spring-seata-dubbo-saga/spring-seata-dubbo-saga-provider/src/main/resources/statelang/reduce_inventory_and_balance.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "Name": "reduceInventoryAndBalance", - "Comment": "reduce inventory then reduce balance in a transaction", - "StartState": "ReduceInventory", - "Version": "0.0.1", - "States": { - "ReduceInventory": { - "Type": "ServiceTask", - "ServiceName": "inventoryAction", - "ServiceMethod": "reduce", - "CompensateState": "CompensateReduceInventory", - "Next": "ChoiceState", - "Input": [ - "$.[businessKey]", - "$.[count]" - ], - "Output": { - "reduceInventoryResult": "$.#root" - }, - "Status": { - "#root == true": "SU", - "#root == false": "FA", - "$Exception{java.lang.Throwable}": "UN" - } - }, - "ChoiceState": { - "Type": "Choice", - "Choices": [ - { - "Expression": "[reduceInventoryResult] == true", - "Next": "ReduceBalance" - } - ], - "Default": "Fail" - }, - "ReduceBalance": { - "Type": "ServiceTask", - "ServiceName": "balanceAction", - "ServiceMethod": "reduce", - "CompensateState": "CompensateReduceBalance", - "Input": [ - "$.[businessKey]", - "$.[amount]", - { - "throwException": "$.[mockReduceBalanceFail]" - } - ], - "Output": { - "compensateReduceBalanceResult": "$.#root" - }, - "Status": { - "#root == true": "SU", - "#root == false": "FA", - "$Exception{java.lang.Throwable}": "UN" - }, - "Catch": [ - { - "Exceptions": [ - "java.lang.Throwable" - ], - "Next": "CompensationTrigger" - } - ], - "Next": "Succeed" - }, - "CompensateReduceInventory": { - "Type": "ServiceTask", - "ServiceName": "inventoryAction", - "ServiceMethod": "compensateReduce", - "Input": [ - "$.[businessKey]" - ] - }, - "CompensateReduceBalance": { - "Type": "ServiceTask", - "ServiceName": "balanceAction", - "ServiceMethod": "compensateReduce", - "Input": [ - "$.[businessKey]" - ] - }, - "CompensationTrigger": { - "Type": "CompensationTrigger", - "Next": "Fail" - }, - "Succeed": { - "Type": "Succeed" - }, - "Fail": { - "Type": "Fail", - "ErrorCode": "PURCHASE_FAILED", - "Message": "purchase failed" - } - } -} \ No newline at end of file