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
官方GIT脚本文件
-- 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
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)