From 55564bfd9e6eebfc39263291d89592cd16f77498 Mon Sep 17 00:00:00 2001 From: zxn <840267340@qq.com> Date: Sun, 26 Jul 2020 11:51:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?seata=20tcc=E6=A8=A1=E5=BC=8F=E6=95=B4?= =?UTF-8?q?=E5=90=88=201=E3=80=81seata=E6=94=B9=E6=88=90=E4=BA=86all=202?= =?UTF-8?q?=E3=80=81=E6=B7=BB=E5=8A=A0tccActionInterceptor=E4=BB=A5?= =?UTF-8?q?=E5=8F=8Ahandler=203=E3=80=81tcc=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=E5=85=A8=E5=B1=80=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 21 +- .../io/jboot/aop/JbootAopInterceptor.java | 5 +- .../interceptor/ActionInterceptorHandler.java | 187 ++++++++++++++++++ .../interceptor/TccActionInterceptor.java | 98 +++++++++ .../fixedinterceptor/FixedInterceptors.java | 2 + .../seata/account/AccountServiceProvider.java | 29 ++- .../test/seata/account/IAccountService.java | 7 + .../io/jboot/test/seata/commons/Account.java | 2 +- .../io/jboot/test/seata/commons/fescar_.sql | 1 + .../seata/service/TccActionOneService.java | 40 ++++ .../service/impl/TccActionOneServiceImpl.java | 55 ++++++ .../test/seata/starter/WebApplication.java | 22 +++ src/test/resources/file.conf | 2 +- 13 files changed, 464 insertions(+), 7 deletions(-) create mode 100644 src/main/java/io/jboot/support/seata/interceptor/ActionInterceptorHandler.java create mode 100644 src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java create mode 100644 src/test/java/io/jboot/test/seata/service/TccActionOneService.java create mode 100644 src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java diff --git a/pom.xml b/pom.xml index f67bf804..cb801082 100644 --- a/pom.xml +++ b/pom.xml @@ -527,7 +527,7 @@ - + + + io.seata + seata-all + ${seata.version} diff --git a/src/main/java/io/jboot/aop/JbootAopInterceptor.java b/src/main/java/io/jboot/aop/JbootAopInterceptor.java index c7ca328d..aaf9913e 100644 --- a/src/main/java/io/jboot/aop/JbootAopInterceptor.java +++ b/src/main/java/io/jboot/aop/JbootAopInterceptor.java @@ -24,7 +24,9 @@ import io.jboot.components.cache.interceptor.JbootCachesEvictInterceptor; import io.jboot.components.limiter.LimiterInterceptor; import io.jboot.support.metric.JbootMetricInterceptor; import io.jboot.support.seata.interceptor.SeataGlobalTransactionalInterceptor; +import io.jboot.support.seata.interceptor.TccActionInterceptor; import io.jboot.support.sentinel.SentinelInterceptor; +import io.jboot.web.fixedinterceptor.FixedInterceptorWapper; import java.util.LinkedList; import java.util.List; @@ -39,7 +41,8 @@ public class JbootAopInterceptor implements Interceptor { new JbootCachesEvictInterceptor(), new JbootCachePutInterceptor(), new JbootCacheInterceptor(), - new SeataGlobalTransactionalInterceptor() + new SeataGlobalTransactionalInterceptor(), + new TccActionInterceptor() }; diff --git a/src/main/java/io/jboot/support/seata/interceptor/ActionInterceptorHandler.java b/src/main/java/io/jboot/support/seata/interceptor/ActionInterceptorHandler.java new file mode 100644 index 00000000..112c53f3 --- /dev/null +++ b/src/main/java/io/jboot/support/seata/interceptor/ActionInterceptorHandler.java @@ -0,0 +1,187 @@ +package io.jboot.support.seata.interceptor; + +import com.alibaba.fastjson.JSON; +import com.jfinal.aop.Invocation; +import io.seata.common.Constants; +import io.seata.common.exception.FrameworkException; +import io.seata.common.util.NetUtil; +import io.seata.common.util.ReflectionUtil; +import io.seata.core.model.BranchType; +import io.seata.rm.DefaultResourceManager; +import io.seata.rm.tcc.TCCResource; +import io.seata.rm.tcc.api.BusinessActionContext; +import io.seata.rm.tcc.api.TwoPhaseBusinessAction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.HashMap; +import java.util.Map; + +/** + * Handler the TCC Participant Aspect : Setting Context, Creating Branch Record + * + * @author zhangsen + */ +public class ActionInterceptorHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(ActionInterceptorHandler.class); + + /** + * Handler the TCC Aspect + * + * @param method the method + * @param arguments the arguments + * @param businessAction the business action + * @return map map + * @throws Throwable the throwable + */ + public void proceed(Method method, Object[] arguments, String xid, TwoPhaseBusinessAction businessAction, + Invocation invocation) { + + //TCC name + String actionName = businessAction.name(); + BusinessActionContext actionContext = new BusinessActionContext(); + actionContext.setXid(xid); + //set action name + actionContext.setActionName(actionName); + Class[] types = method.getParameterTypes(); + Parameter[] parameters = invocation.getMethod().getParameters(); + int argIndex = 0; + for (Class cls : types) { + if (cls.getName().equals(BusinessActionContext.class.getName())) { + arguments[argIndex] = actionContext; + break; + } + argIndex++; + } + //Creating Branch Record + String branchId = doTccActionLogStore(method,parameters, arguments, businessAction, actionContext); + try { + registryResource(method, invocation.getTarget(),types, businessAction); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + actionContext.setBranchId(branchId); + + invocation.invoke(); + } + + /** + * Creating Branch Record + * + * @param method the method + * @param arguments the arguments + * @param businessAction the business action + * @param actionContext the action context + * @return the string + */ + protected String doTccActionLogStore(Method method, Parameter[] parameters , Object[] arguments, TwoPhaseBusinessAction businessAction, + BusinessActionContext actionContext) { + String actionName = actionContext.getActionName(); + String xid = actionContext.getXid(); + // + Map context = fetchActionRequestContext(method, arguments,parameters); + context.put(Constants.ACTION_START_TIME, System.currentTimeMillis()); + + //init business context + initBusinessContext(context, method, businessAction); + //Init running environment context + initFrameworkContext(context); + actionContext.setActionContext(context); + + //init applicationData + Map applicationContext = new HashMap<>(4); + applicationContext.put(Constants.TCC_ACTION_CONTEXT, context); + String applicationContextStr = JSON.toJSONString(applicationContext); + try { + //registry branch record + Long branchId = DefaultResourceManager.get().branchRegister(BranchType.TCC, actionName, null, xid, + applicationContextStr, null); + return String.valueOf(branchId); + } catch (Throwable t) { + String msg = String.format("TCC branch Register error, xid: %s", xid); + LOGGER.error(msg, t); + throw new FrameworkException(t, msg); + } + } + + /** + * Init running environment context + * + * @param context the context + */ + protected void initFrameworkContext(Map context) { + try { + context.put(Constants.HOST_NAME, NetUtil.getLocalIp()); + } catch (Throwable t) { + LOGGER.warn("getLocalIP error", t); + } + } + + /** + * Init business context + * + * @param context the context + * @param method the method + * @param businessAction the business action + */ + protected void initBusinessContext(Map context, Method method, + TwoPhaseBusinessAction businessAction) { + if (method != null) { + //the phase one method name + context.put(Constants.PREPARE_METHOD, method.getName()); + } + if (businessAction != null) { + //the phase two method name + context.put(Constants.COMMIT_METHOD, businessAction.commitMethod()); + context.put(Constants.ROLLBACK_METHOD, businessAction.rollbackMethod()); + context.put(Constants.ACTION_NAME, businessAction.name()); + } + } + + /** + * Extracting context data from parameters, add them to the context + * + * @param method the method + * @param arguments the arguments + * @return map map + */ + protected Map fetchActionRequestContext(Method method, Object[] arguments,Parameter[] parameters) { + Map context = new HashMap<>(8); + int x = 0; + for (Parameter p : parameters) { + if (!p.isNamePresent()) { + // 必须通过添加 -parameters 进行编译,才可以获取 Parameter 的编译前的名字 + throw new RuntimeException(" Maven or IDE config is error. see http://www.jfinal.com/doc/3-3 "); + } + if (!"io.seata.rm.tcc.api.BusinessActionContext".equals(p.getType().getName())) { + context.put(p.getName(), arguments[x]); + } + x++; + } + return context; + } + + public void registryResource(Method m, Object interfaceClass, Class[] arguments, TwoPhaseBusinessAction businessAction) throws NoSuchMethodException { + if (businessAction != null) { + TCCResource tccResource = new TCCResource(); + tccResource.setActionName(businessAction.name()); + tccResource.setTargetBean(interfaceClass); + tccResource.setPrepareMethod(m); + tccResource.setCommitMethodName(businessAction.commitMethod()); + tccResource.setCommitMethod(ReflectionUtil + .getMethod(interfaceClass.getClass(), businessAction.commitMethod(), + new Class[] {BusinessActionContext.class})); + tccResource.setRollbackMethodName(businessAction.rollbackMethod()); + tccResource.setRollbackMethod(ReflectionUtil + .getMethod(interfaceClass.getClass(), businessAction.rollbackMethod(), + new Class[] {BusinessActionContext.class})); + //registry tcc resource + DefaultResourceManager.get().registerResource(tccResource); + } + } + + +} diff --git a/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java b/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java new file mode 100644 index 00000000..82d7e7e4 --- /dev/null +++ b/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java @@ -0,0 +1,98 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * Licensed 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 io.jboot.support.seata.interceptor; + +import com.jfinal.aop.Interceptor; +import com.jfinal.aop.Invocation; +import io.jboot.web.fixedinterceptor.FixedInterceptor; +import io.seata.common.util.StringUtils; +import io.seata.core.context.RootContext; +import io.seata.core.model.BranchType; +import io.seata.rm.tcc.api.TwoPhaseBusinessAction; +import io.seata.rm.tcc.remoting.RemotingDesc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Method; + + +/** + * TCC Interceptor + * + * @author zhangsen + */ +public class TccActionInterceptor implements Interceptor,FixedInterceptor { + + private static final Logger LOGGER = LoggerFactory.getLogger(TccActionInterceptor.class); + + private ActionInterceptorHandler actionInterceptorHandler = new ActionInterceptorHandler(); + + /** + * remoting bean info + */ + protected RemotingDesc remotingDesc; + + /** + * Instantiates a new Tcc action interceptor. + */ + public TccActionInterceptor() { + + } + + /** + * Instantiates a new Tcc action interceptor. + * + * @param remotingDesc the remoting desc + */ + public TccActionInterceptor(RemotingDesc remotingDesc) { + this.remotingDesc = remotingDesc; + } + + @Override + public void intercept(Invocation inv) { + if (!RootContext.inGlobalTransaction()) { + //not in transaction + inv.invoke(); + return ; + } + Method method = inv.getMethod(); + TwoPhaseBusinessAction businessAction = method.getAnnotation(TwoPhaseBusinessAction.class); + //try method + if (businessAction != null) { + //save the xid + String xid = RootContext.getXID(); + //clear the context + String previousBranchType = RootContext.getBranchType(); + RootContext.bindBranchType(BranchType.TCC); + try { + Object[] methodArgs = inv.getArgs(); + //Handler the TCC Aspect + actionInterceptorHandler.proceed(method, methodArgs, xid, businessAction, inv); + return; + } finally { + RootContext.unbindBranchType(); + //restore the TCC branchType if exists + if (StringUtils.equals(BranchType.TCC.name(), previousBranchType)) { + RootContext.bindBranchType(BranchType.TCC); + } + } + } else { + inv.invoke(); + } + return; + } + +} diff --git a/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java b/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java index 3dad2418..ca716ea5 100644 --- a/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java +++ b/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java @@ -20,6 +20,7 @@ import io.jboot.components.limiter.LimiterInterceptor; import io.jboot.support.jwt.JwtInterceptor; import io.jboot.support.metric.JbootMetricInterceptor; import io.jboot.support.seata.interceptor.SeataGlobalTransactionalInterceptor; +import io.jboot.support.seata.interceptor.TccActionInterceptor; import io.jboot.support.sentinel.SentinelInterceptor; import io.jboot.support.shiro.JbootShiroInterceptor; import io.jboot.web.validate.ParaValidateInterceptor; @@ -56,6 +57,7 @@ public class FixedInterceptors { new FixedInterceptorWapper(new JbootShiroInterceptor(), 50), new FixedInterceptorWapper(new JbootMetricInterceptor(), 60), new FixedInterceptorWapper(new SeataGlobalTransactionalInterceptor(), 80), + new FixedInterceptorWapper(new TccActionInterceptor(), 90), }; private List userInters = new ArrayList<>(); diff --git a/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java b/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java index 4f9037c9..78cd793e 100644 --- a/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java +++ b/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java @@ -1,24 +1,47 @@ package io.jboot.test.seata.account; +import io.jboot.aop.annotation.Bean; import io.jboot.components.rpc.annotation.RPCBean; import io.jboot.service.JbootServiceBase; import io.jboot.test.seata.commons.Account; @RPCBean +@Bean public class AccountServiceProvider extends JbootServiceBase implements IAccountService { - private static Account dao = new Account().dao(); + private static Account dao = new Account(); public boolean deposit(Integer accountId, Integer money) { Account account = dao.findById(accountId); - account.set("Money", account.getInt("Money") + money); + account.set("money", account.getInt("money") + money); if (money > 1000) { throw new RuntimeException(AccountServiceProvider.class.getSimpleName()+"Dubbo Seata Exception By Hobbit"); } - return account.update(); + return account.saveOrUpdate(); } + @Override + public boolean updateStore(String account, Integer money) { + Account account1 = dao.findFirst("select * from seata_account where account = ? ", account); + account1.set("store", account1.getInt("store") + money); + return account1.saveOrUpdate(); + } + + @Override + public boolean updateRollbackStore(String account, Integer money) { + Account account1 = dao.findFirst("select * from seata_account where account = ? ", account); + account1.set("store", account1.getInt("store") - money); + return account1.saveOrUpdate(); + } + + @Override + public boolean update(String account, Integer money) { + Account account1 = dao.findFirst("select * from seata_account where account = ? ", account); + account1.set("store", account1.getInt("store") - money); + account1.set("money", account1.getInt("money") - money); + return account1.saveOrUpdate(); + } } diff --git a/src/test/java/io/jboot/test/seata/account/IAccountService.java b/src/test/java/io/jboot/test/seata/account/IAccountService.java index 90d5f37e..ec971516 100644 --- a/src/test/java/io/jboot/test/seata/account/IAccountService.java +++ b/src/test/java/io/jboot/test/seata/account/IAccountService.java @@ -1,5 +1,12 @@ package io.jboot.test.seata.account; public interface IAccountService { + public boolean deposit(Integer accountId, Integer money); + + public boolean updateStore(String account, Integer money); + + public boolean updateRollbackStore(String account, Integer money); + + public boolean update(String accountId, Integer money); } diff --git a/src/test/java/io/jboot/test/seata/commons/Account.java b/src/test/java/io/jboot/test/seata/commons/Account.java index 8c26ca42..ee85a877 100644 --- a/src/test/java/io/jboot/test/seata/commons/Account.java +++ b/src/test/java/io/jboot/test/seata/commons/Account.java @@ -5,7 +5,7 @@ import com.jfinal.plugin.activerecord.IBean; import io.jboot.db.annotation.Table; import io.jboot.db.model.JbootModel; -@Table(tableName = "seata_account", primaryKey = "ID") +@Table(tableName = "seata_account", primaryKey = "id") public class Account extends JbootModel implements IBean { /** * diff --git a/src/test/java/io/jboot/test/seata/commons/fescar_.sql b/src/test/java/io/jboot/test/seata/commons/fescar_.sql index 1c69d007..63039bb2 100644 --- a/src/test/java/io/jboot/test/seata/commons/fescar_.sql +++ b/src/test/java/io/jboot/test/seata/commons/fescar_.sql @@ -10,6 +10,7 @@ CREATE TABLE `seata_account` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Account` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `Money` int(11) NULL DEFAULT NULL, + `store` int(11) NULL DEFAULT NULL, PRIMARY KEY (`ID`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; diff --git a/src/test/java/io/jboot/test/seata/service/TccActionOneService.java b/src/test/java/io/jboot/test/seata/service/TccActionOneService.java new file mode 100644 index 00000000..b73596f0 --- /dev/null +++ b/src/test/java/io/jboot/test/seata/service/TccActionOneService.java @@ -0,0 +1,40 @@ +package io.jboot.test.seata.service; + +import io.seata.rm.tcc.api.BusinessActionContext; +import io.seata.rm.tcc.api.BusinessActionContextParameter; + +/** + * program: seata + * description: ${description} + * author: zxn + * create: 2020-07-25 22:29 + **/ +public interface TccActionOneService { + + /** + * Prepare boolean. + * + * @param actionContext the action context + * @param account + * @return the boolean + */ + + public boolean prepare(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "account") String account, @BusinessActionContextParameter(paramName = "money") int money, + @BusinessActionContextParameter(paramName = "flag") boolean flag); + + /** + * 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); +} diff --git a/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java b/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java new file mode 100644 index 00000000..d2f68a6a --- /dev/null +++ b/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java @@ -0,0 +1,55 @@ +package io.jboot.test.seata.service.impl; + +import com.jfinal.aop.Inject; +import com.jfinal.kit.StrKit; +import io.jboot.aop.annotation.Bean; +import io.jboot.test.seata.account.IAccountService; +import io.jboot.test.seata.service.TccActionOneService; +import io.seata.rm.tcc.api.BusinessActionContext; +import io.seata.rm.tcc.api.BusinessActionContextParameter; +import io.seata.rm.tcc.api.TwoPhaseBusinessAction; + +/** + * program: seata + * description: ${description} + * author: zxn + * create: 2020-07-25 22:39 + **/ +@Bean +public class TccActionOneServiceImpl implements TccActionOneService { + + @Inject + private IAccountService accountService; + + @Override + @TwoPhaseBusinessAction(name = "TccActionOne" , commitMethod = "commit", rollbackMethod = "rollback") + public boolean prepare(BusinessActionContext actionContext, String account,int money, boolean flag) { + System.out.println("actionContext获取Xid prepare>>> "+actionContext.getXid()); + System.out.println("actionContext获取TCC参数 prepare>>> "+actionContext.getActionContext("account")); + accountService.updateStore(account, money); + /* if (flag) { + throw new RuntimeException("you have fail"); + }*/ + return true; + } + + @Override + public boolean commit(BusinessActionContext actionContext) { + System.out.println("actionContext获取TCC参数 commit >>> "+ actionContext.getActionContext("account") + ": " + + actionContext.getActionContext("money")); + String account = (String) actionContext.getActionContext("account"); + int money = (int) actionContext.getActionContext("money"); + accountService.update(account, money); + return true; + } + + @Override + public boolean rollback(BusinessActionContext actionContext) { + System.out.println("actionContext获取TCC参数 rollback >>> "+ actionContext.getActionContext("account") + ": " + + actionContext.getActionContext("money")); + String account = (String) actionContext.getActionContext("account"); + int money = (int) actionContext.getActionContext("money"); + accountService.updateRollbackStore(account, money); + return true; + } +} diff --git a/src/test/java/io/jboot/test/seata/starter/WebApplication.java b/src/test/java/io/jboot/test/seata/starter/WebApplication.java index ac1201df..4132d4e8 100644 --- a/src/test/java/io/jboot/test/seata/starter/WebApplication.java +++ b/src/test/java/io/jboot/test/seata/starter/WebApplication.java @@ -2,7 +2,9 @@ package io.jboot.test.seata.starter; import com.jfinal.aop.Inject; import io.jboot.app.JbootApplication; +import io.jboot.support.seata.annotation.SeataGlobalTransactional; import io.jboot.test.seata.business.BusinessServiceProvider; +import io.jboot.test.seata.service.TccActionOneService; import io.jboot.web.controller.JbootController; import io.jboot.web.controller.annotation.RequestMapping; @@ -26,6 +28,13 @@ public class WebApplication extends JbootController { JbootApplication.setBootArg("jboot.seata.applicationId", "Dubbo_Seata_Business_Service"); JbootApplication.setBootArg("jboot.seata.txServiceGroup", "dubbo_seata_tx_group"); + JbootApplication.setBootArg("jboot.datasource.type", "mysql"); + JbootApplication.setBootArg("jboot.datasource.url", "jdbc:mysql://127.0.0.1:3306/mini?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull"); + JbootApplication.setBootArg("jboot.datasource.user", "root"); + JbootApplication.setBootArg("jboot.datasource.password", "zhang123"); + JbootApplication.setBootArg("jboot.model.unscanPackage", "*"); + JbootApplication.setBootArg("jboot.model.scanPackage", "io.jboot.test.seata.commons"); + JbootApplication.run(args); } @@ -33,6 +42,9 @@ public class WebApplication extends JbootController { @Inject private BusinessServiceProvider businessServiceProvider; + @Inject + private TccActionOneService tccActionOneService; + public void index() { System.out.println("WebApplication.index()"); @@ -40,4 +52,14 @@ public class WebApplication extends JbootController { businessServiceProvider.deposit(1); renderText("ok"); } + + @SeataGlobalTransactional(timeoutMills = 300000, name = "Seata_Business_Transactional_TccOne") + public void tccOne(){ + tccActionOneService.prepare(null, "Hobbit", 10, getParaToBoolean("flag")); + if (getParaToBoolean("flag")) { + throw new RuntimeException("you have fail"); + } + renderJson("you are sucess"); + } + } diff --git a/src/test/resources/file.conf b/src/test/resources/file.conf index 0660bf81..97512d1d 100644 --- a/src/test/resources/file.conf +++ b/src/test/resources/file.conf @@ -28,7 +28,7 @@ transport { } service { #vgroup->rgroup - vgroup_mapping.dubbo_seata_tx_group = "default" + vgroupMapping.dubbo_seata_tx_group = "default" #only support single node default.grouplist = "127.0.0.1:8091" #degrade current not support -- Gitee From ea45561ece8e8d4918f9006c43235512a59897a5 Mon Sep 17 00:00:00 2001 From: zxn <840267340@qq.com> Date: Sun, 26 Jul 2020 12:08:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?seata=20tcc=E6=A8=A1=E5=BC=8F=E6=95=B4?= =?UTF-8?q?=E5=90=88=201=E3=80=81seata=E6=94=B9=E6=88=90=E4=BA=86all=202?= =?UTF-8?q?=E3=80=81=E6=B7=BB=E5=8A=A0tccActionInterceptor=E4=BB=A5?= =?UTF-8?q?=E5=8F=8Ahandler=203=E3=80=81tcc=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=E5=85=A8=E5=B1=80=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 13 +++++++------ src/main/java/io/jboot/aop/JbootAopInterceptor.java | 3 +-- .../seata/interceptor/TccActionInterceptor.java | 2 +- .../web/fixedinterceptor/FixedInterceptors.java | 2 +- .../test/seata/account/AccountServiceProvider.java | 2 +- .../jboot/test/seata/account/IAccountService.java | 1 + .../java/io/jboot/test/seata/commons/Account.java | 1 + .../java/io/jboot/test/seata/commons/fescar_.sql | 2 +- .../test/seata/service/TccActionOneService.java | 2 +- .../seata/service/impl/TccActionOneServiceImpl.java | 4 ++-- .../io/jboot/test/seata/starter/WebApplication.java | 4 ++-- src/test/resources/file.conf | 2 +- 12 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index cb801082..6a4085aa 100644 --- a/pom.xml +++ b/pom.xml @@ -586,14 +586,10 @@ seata-config-core - --> - - io.seata - seata-all - ${seata.version} + io.seata seata-common @@ -605,8 +601,13 @@ logback-classic - + --> + + io.seata + seata-all + ${seata.version} + net.oschina.j2cache diff --git a/src/main/java/io/jboot/aop/JbootAopInterceptor.java b/src/main/java/io/jboot/aop/JbootAopInterceptor.java index aaf9913e..b1cbb561 100644 --- a/src/main/java/io/jboot/aop/JbootAopInterceptor.java +++ b/src/main/java/io/jboot/aop/JbootAopInterceptor.java @@ -149,6 +149,5 @@ public class JbootAopInterceptor implements Interceptor { } } } - - + } diff --git a/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java b/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java index 82d7e7e4..2d35d8b5 100644 --- a/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java +++ b/src/main/java/io/jboot/support/seata/interceptor/TccActionInterceptor.java @@ -64,7 +64,7 @@ public class TccActionInterceptor implements Interceptor,FixedInterceptor { @Override public void intercept(Invocation inv) { if (!RootContext.inGlobalTransaction()) { - //not in transaction + // not in transaction inv.invoke(); return ; } diff --git a/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java b/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java index ca716ea5..d7fa8021 100644 --- a/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java +++ b/src/main/java/io/jboot/web/fixedinterceptor/FixedInterceptors.java @@ -57,7 +57,7 @@ public class FixedInterceptors { new FixedInterceptorWapper(new JbootShiroInterceptor(), 50), new FixedInterceptorWapper(new JbootMetricInterceptor(), 60), new FixedInterceptorWapper(new SeataGlobalTransactionalInterceptor(), 80), - new FixedInterceptorWapper(new TccActionInterceptor(), 90), + new FixedInterceptorWapper(new TccActionInterceptor(), 90) }; private List userInters = new ArrayList<>(); diff --git a/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java b/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java index 78cd793e..720af52e 100644 --- a/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java +++ b/src/test/java/io/jboot/test/seata/account/AccountServiceProvider.java @@ -17,7 +17,7 @@ public class AccountServiceProvider extends JbootServiceBase implements account.set("money", account.getInt("money") + money); if (money > 1000) { - throw new RuntimeException(AccountServiceProvider.class.getSimpleName()+"Dubbo Seata Exception By Hobbit"); + throw new RuntimeException(AccountServiceProvider.class.getSimpleName()+"Dubbo Seata Exception By Hobbit "); } return account.saveOrUpdate(); diff --git a/src/test/java/io/jboot/test/seata/account/IAccountService.java b/src/test/java/io/jboot/test/seata/account/IAccountService.java index ec971516..656ef2d4 100644 --- a/src/test/java/io/jboot/test/seata/account/IAccountService.java +++ b/src/test/java/io/jboot/test/seata/account/IAccountService.java @@ -9,4 +9,5 @@ public interface IAccountService { public boolean updateRollbackStore(String account, Integer money); public boolean update(String accountId, Integer money); + } diff --git a/src/test/java/io/jboot/test/seata/commons/Account.java b/src/test/java/io/jboot/test/seata/commons/Account.java index ee85a877..0b535ca1 100644 --- a/src/test/java/io/jboot/test/seata/commons/Account.java +++ b/src/test/java/io/jboot/test/seata/commons/Account.java @@ -12,4 +12,5 @@ public class Account extends JbootModel implements IBean { */ private static final long serialVersionUID = 1L; + } diff --git a/src/test/java/io/jboot/test/seata/commons/fescar_.sql b/src/test/java/io/jboot/test/seata/commons/fescar_.sql index 63039bb2..07c6c16e 100644 --- a/src/test/java/io/jboot/test/seata/commons/fescar_.sql +++ b/src/test/java/io/jboot/test/seata/commons/fescar_.sql @@ -10,7 +10,7 @@ CREATE TABLE `seata_account` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Account` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `Money` int(11) NULL DEFAULT NULL, - `store` int(11) NULL DEFAULT NULL, + `store` int(10) NULL DEFAULT NULL, PRIMARY KEY (`ID`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; diff --git a/src/test/java/io/jboot/test/seata/service/TccActionOneService.java b/src/test/java/io/jboot/test/seata/service/TccActionOneService.java index b73596f0..69be518b 100644 --- a/src/test/java/io/jboot/test/seata/service/TccActionOneService.java +++ b/src/test/java/io/jboot/test/seata/service/TccActionOneService.java @@ -20,7 +20,7 @@ public interface TccActionOneService { */ public boolean prepare(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "account") String account, @BusinessActionContextParameter(paramName = "money") int money, - @BusinessActionContextParameter(paramName = "flag") boolean flag); + @BusinessActionContextParameter(paramName = "flag") boolean flag); /** * Commit boolean. diff --git a/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java b/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java index d2f68a6a..63ca7c4c 100644 --- a/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java +++ b/src/test/java/io/jboot/test/seata/service/impl/TccActionOneServiceImpl.java @@ -27,9 +27,9 @@ public class TccActionOneServiceImpl implements TccActionOneService { System.out.println("actionContext获取Xid prepare>>> "+actionContext.getXid()); System.out.println("actionContext获取TCC参数 prepare>>> "+actionContext.getActionContext("account")); accountService.updateStore(account, money); - /* if (flag) { + if (flag) { throw new RuntimeException("you have fail"); - }*/ + } return true; } diff --git a/src/test/java/io/jboot/test/seata/starter/WebApplication.java b/src/test/java/io/jboot/test/seata/starter/WebApplication.java index 4132d4e8..970bfc0a 100644 --- a/src/test/java/io/jboot/test/seata/starter/WebApplication.java +++ b/src/test/java/io/jboot/test/seata/starter/WebApplication.java @@ -56,9 +56,9 @@ public class WebApplication extends JbootController { @SeataGlobalTransactional(timeoutMills = 300000, name = "Seata_Business_Transactional_TccOne") public void tccOne(){ tccActionOneService.prepare(null, "Hobbit", 10, getParaToBoolean("flag")); - if (getParaToBoolean("flag")) { + /*if (getParaToBoolean("flag")) { throw new RuntimeException("you have fail"); - } + }*/ renderJson("you are sucess"); } diff --git a/src/test/resources/file.conf b/src/test/resources/file.conf index 97512d1d..03888e60 100644 --- a/src/test/resources/file.conf +++ b/src/test/resources/file.conf @@ -28,7 +28,7 @@ transport { } service { #vgroup->rgroup - vgroupMapping.dubbo_seata_tx_group = "default" + vgroupMapping.dubbo_seata_tx_group ="default" #only support single node default.grouplist = "127.0.0.1:8091" #degrade current not support -- Gitee