很久没写博客了…
按照 seata-work-shop 中的步骤,下载并启动 Seata 服务器.
在每一个分片数据库实例中执创建 undo_log
表(以 MySQL 为例).
CREATE TABLE IF NOT EXISTS `undo_log`
(
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
`branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(100) 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 NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME NOT NULL COMMENT 'modify datetime',
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
在 classpath 中增加 seata.conf
文件.
client {
application.id = example ## 应用唯一主键
transaction.service.group = my_test_tx_group ## 所属事务组
}
1.seata-samples demo,启动 seata server,运行 io.seata.server.ServerApplication
检查 file.conf 里的 server 配置端口 和 seata 服务起的端口一致.
默认 seata server 提供的服务端口就是 8091.
service {
#transaction service group mapping
vgroupMapping.my_test_tx_group = "default"
#only support when registry.type=file, please don't set multiple addresses
default.grouplist = "127.0.0.1:8091"
#degrade, current not support
enableDegrade = false
#disable seata
disableGlobalTransaction = false
}
运行demo io.seata.samples.springboot.SeataSpringbootApp
网页请求 http://127.0.0.1:9999/demo/asset/assign
这个demo 是一个跨两个表,最后抛出异常,seata 会自动回滚该事务.
https://github.com/seata/seata-samples.git