Spring Cloud + Nacos + MybatisPlus 集成 Seata
架构依赖包版本说明
- Spring Cloud Hoxton.SR10
- Spring cloud alibaba 2.2.1.RELEASE
- Spring boot 2.3.8.RELEASE
- Mybatis-plus 3.4.1
- mysql-connector-java 8.0.17
- Nacos 1.4.1
- Seata 1.4.1
集成步骤
-
下载,启动Nacos,此处省略
-
下载,配置,并启动 seata
- 点击进入:https://github.com/seata/seata/releases
- 编辑registry.conf,关键配置如下
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = ""
password = ""
}
}
- 编辑file.conf,关键配置如下:
store {
## store mode: file、db、redis
mode = "db"
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.cj.jdbc.Driver"
url = "jdbc:mysql://xxxx:3306/seata_db"
user = "xxx"
password = "xxx"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
- 启动seata:.\seata-server.bat,端口默认占用 8091
- 集成到服务消费者
- 添加依赖(下面版本为定制化后定义的版本):
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.4.0-BETA-3</version>
</dependency>
- 拷贝服务端的registry.conf到工程下的resources目录中,内容无需修改
- 创建file.conf到resources目录下,官网有提供,可以下一个模板过来
- 修改file.conf内容
service {
disableGlobalTransaction = false
vgroupMapping.stdv6_tx_group = "default"
enableDegrade = false
#disable seata
disableGlobalTransaction = false
max.commit.retry.timeout = "-1"
max.rollback.retry.timeout = "-1"
}
- 配置seata相关yml配置
# seata相关配置
seata:
tx-service-group: stdv6_tx_group
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: "SEATA_GROUP"
版权声明:本文为qq_36381800原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END