开启seata事务文档书写

This commit is contained in:
life 2023-08-07 17:44:48 +08:00
parent dccfb48361
commit cfb318edbe
2 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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: