springcloud 集成 seata + nacos踩坑记录
参考文章:文章1和文章2和文章3版本对应关系https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E集成seata当前文章使用的是若依微服务中的基础seata方式,但是操作下来,各种问题,需要按照若依进行的步骤进行集成后,再做如下修改找到对应的seata依赖<depend
版本对应关系
https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
集成seata
当前文章使用的是若依微服务中的基础seata方式,但是操作下来,各种问题,需要按照若依进行的步骤进行集成后,再做如下修改
- 找到对应的seata依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
改为如下
<!-- SpringBoot Seata 集成相关-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<!--spring-cloud-starter-alibaba-seata集成的是1.2.0版本的seata,要用1.4.2的需要排除掉集成的-->
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.4.2</version>
</dependency>
<!-- 1.4.2 因为序列化问题导致事物不回滚-->
<!-- 修改nacos中seata配置。jackson 改为kryo。并引入依赖-->
<!-- client.undo.logSerialization = kryo-->
<dependency>
<groupId>com.esotericsoftware.kryo</groupId>
<artifactId>kryo</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>0.44</version>
</dependency>
<!-- SpringBoot Seata 集成相关-->
- 修改config.txt文件
注意第一行要与yaml中配置一致
修改store.db.password的密码为自己数据库的密码
添加一行: client.undo.logSerializatio=kryo
service.vgroupMapping.ruoyi-system-group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/ry-seata?useUnicode=true
store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
client.undo.logSerializatio=kryo
- 集成seata到nacos配置中心
注意使用git的 Git Bash执行shll 脚本
神坑 ,enableAutoDataSourceProxy无法关闭
https://blog.csdn.net/dai909237869/article/details/124093302
我测试了,enable-auto-data-source-proxy是可以生效的,原因就不清楚了
1.4.2及以下版本回滚时抛出Cannot construct instance of java.time.LocalDateTime
?
A:
升级1.5.0及以上版本
B:
不要使用mysql driver8.0.x版本
C:
引入kryo相关依赖
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>0.42</version>
</dependency>
如果配置中心是file,依赖是seata-all,请在应用的file.conf文件中添加如下配置
client {
undo {
logSerialization = "kryo"
}
}
如果配置中心是file,依赖是seata-spring-boot-starter,使用yml 自行转成yml格式即可
seata.client.undo.logSerialization=kryo
如果是第三方配置中心如nacos
请在seata使用的配置相关group,namespace上添加dataid: client.undo.logSerialization,值为kryo
D:
修改数据库表中的datetime类型为timestamp
E:
参考此pr做法,可以用类覆盖或SPI方式扩展新的解析方式处理
自己遇到的问题
不管怎么修改,从nacos依赖版本1.4.2,seata版本改为1.5.0,还是将序列化解析方式修改为kryo,或是将问题,一直会在undo_log表中出现log_status=0的值,导致事务一直重试,导致事务回滚失败,
查了两天,最后把分布式事务关联的所有表中的datetime类型改为了timestamp后终于可以了
更多推荐
所有评论(0)