From cfb318edbe1eead3435195a3c2c9e1140f01c229 Mon Sep 17 00:00:00 2001 From: life <13122192336@163.com> Date: Mon, 7 Aug 2023 17:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=90=AFseata=E4=BA=8B=E5=8A=A1?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B9=A6=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/core/tx.md | 22 +++++++++++++++++++ .../src/main/resources/application.yml | 6 ++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/zh/core/tx.md b/docs/zh/core/tx.md index 8f199f41..6caa1776 100644 --- a/docs/zh/core/tx.md +++ b/docs/zh/core/tx.md @@ -124,3 +124,25 @@ public void doSomething(){ >假设在回滚的时候,恰好其中一个数据库出现了异常(比如 网络问题,数据库崩溃),此时,可能只有一个数据库的数据正常回滚(rollback)。 > 但无论如何,MyBatis-Flex 都会保证在同一个 `@Transactional` 中的多个数据源,保持相同的 commit 或者 rollback 行为。 + +## 支持seata事务 +1. 首先,先了解事务的基础(自行百度), +2. 在了解seata事务的项目 官网地址:https://seata.io/zh-cn/docs +3. 然后根据官方的[快速开始](https://seata.io/zh-cn/docs/user/quickstart.html)在下载最新版的seata-server并在本地跑起一个 +4. seata-server服务 +5. 然后使用[mybatis-flex-test](https://gitee.com/mybatis-flex/mybatis-flex/tree/main/mybatis-flex-test)模块 下面的mybatis-flex-spring-boot-seata进行测试 +>此demo只是一个纯演示的demo,模仿的是[官方事例](https://github.com/seata/seata-samples/tree/master/springboot-mybatis) +进行整合,微服务合并成一个多数据源进行测试,当然,这种方法是不提倡的,seata事务并且本地多数据源的方式可能本身就存在设计思路问题,可能存在过度设计,此demo只是作为一个演示。 +### 注意事项 +>使用seata的时候必须数据源代理 +`seata.enable-auto-data-source-proxy: false` + +`pom`自行引入[seata-spring-boot-starter](https://mvnrepository.com/artifact/io.seata/seata-spring-boot-starter)依赖, + +application.yml需要配置如下参数 +1. `mybatis-flex.seata-config.enable` + + 配置含义:seata事务是否开启,true开启,默认false关闭 +2. `mybatis-flex.seata-config.seata-mode` + + 默认启动的事务类型,目前只支持XA或者AT,默认AT diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml b/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml index 7b039f84..97c7b42c 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml +++ b/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml @@ -1,7 +1,7 @@ mybatis-flex: seata-config: - enable: true - seata-mode: XA + enable: true #启动seata + seata-mode: XA #xa或者ta datasource: accountdb: url: jdbc:mysql://127.0.0.1:3306/db_account @@ -21,7 +21,7 @@ seata: enabled: true application-id: business-service tx-service-group: my_test_tx_group - enable-auto-data-source-proxy: false + enable-auto-data-source-proxy: false #必须 # use-jdk-proxy: false client: rm: