seata springcloud整合教程与遇到的坑
SEATA概要
seata 是alibaba 出的一款分布式事务管理器,他有侵入性小,实现简单等特点。我们能够使用seata 实现分布式事务管理,
是微服务必备的组件。他可以实现在微服务之间的事务管理,也可以实现多个数据源的事务管理。
seata 在阿里内部,和众多的公司都有应用,因此我们可以放心的使用它。
依赖
<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注册中心相同
nacos:
application: seata-server
server-addr: ${PSR_NACOS:localhost:8848}
namespace: test
group: application
cluster: default
config:
type: nacos # 与seata配置中心相同
nacos:
server-addr: ${PSR_NACOS:localhost:8848}
group: seata
namespace: test
service:
vgroup-mapping:
my_test_tx_group: default # 事务分组名
disable-global-transaction: false
client:
rm:
report-success-enable: false
启用全局事务
@GlobalTransactional
到此这篇关于seata springcloud整合教程与遇到的坑的文章就介绍到这了,更多相关seata springcloud整合内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Java异步编程之Callbacks与Futures模型详解
这篇文章主要为大家详细介绍了Java异步编程中Callbacks与Futures模型的使用,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下2023-03-03
Elasticsearch percolate 查询示例详解
这篇文章主要为大家介绍了Elasticsearch percolate 查询示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-01-01
springboot启动的注意事项之不同包下有同样名字的class类问题
这篇文章主要介绍了springboot启动的注意事项之不同包下有同样名字的class类问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-06-06


最新评论