高可用部署seata环境 springcloud整合
依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
建表
AT模式客户端服务的数据库都需要建表undo_log
否则报错
java.sql.SQLSyntaxErrorException: Table ‘psr_enterprise_control_test.undo_log’ doesn’t exist
-- for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE IF NOT EXISTS `undo_log`
(
`branch_id` BIGINT NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(128) NOT NULL COMMENT 'global transaction id',
`context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
`log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` DATETIME(6) NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime',
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
配置
application.yml
seata:
enabled: true
enable-auto-data-source-proxy: true
tx-service-group: my_test_tx_group # 与seata.service.vgroup-mapping一致
registry:
type: nacos # 与SEATA-SERVER配置一致
nacos:
application: seata-server # 与SEATA-SERVER配置一致
server-addr: ${PSR_NACOS:localhost:8848}
namespace: test # 与SEATA-SERVER配置一致
group: SEATA_GROUP # 与SEATA-SERVER配置一致
cluster: default
config:
type: nacos # 与seata配置中心相同
nacos:
server-addr: ${PSR_NACOS:localhost:8848}
group: SEATA_GROUP # 与SEATA-SERVER配置一致
namespace: test # 与SEATA-SERVER配置一致
service:
vgroup-mapping:
my_test_tx_group: default # 事务分组名
disable-global-transaction: false # 默认开启全局事务
client:
rm:
report-success-enable: false # 不启用日志可以提高性能
启用全局事务
@GlobalTransactional
异常处理
- 无法启动事务报错:
io.seata.common.exception.FrameworkException: No available service
at io.seata.core.rpc.netty.AbstractNettyRemotingClient.loadBalance(AbstractNettyRemotingClient.java:257) ~[seata-all-1.3.0.jar:1.3.0]
原因:无法通过NACOS注册中心找到SEATA-SERVER服务
处理:检查客户端配置中seata.registry和seata.config配置项目是否与SEATA-SERVER中配置一致
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
2020-04-11 spring 启动时自动运行
2020-04-11 spring cloud oauth2授权服务 默认tokenService配置源码
2020-04-11 spring cloud 搭建oauth2授权服务 使用redis存储令牌
2020-04-11 spring cloud oauth2授权服务 clientDetails配置源码
2020-04-11 spring 验证框架
2020-04-11 IDEA 插件整理
2020-04-11 spring security笔记 默认登陆页面源码