本文采用的seata-server-1.4.0.zip
下载下来直接解压,因为使用nacos做注册中心的参考文档很多,所以本文使用eureka,配置简单。
service {
#transaction service group mapping
## 指定group名
vgroup_mapping.my_test_tx_group = "seata-server" #可自行定义组名
#only support when registry.type=file, please don't set multiple addresses
default.grouplist = "127.0.0.1:8091" #默认端口
#disable seata
disableGlobalTransaction = false
}
CREATE TABLE `global_table` (
`xid` varchar(128) NOT NULL,
`transaction_id` bigint DEFAULT NULL,
`status` tinyint NOT NULL,
`application_id` varchar(32) DEFAULT NULL,
`transaction_service_group` varchar(32) DEFAULT NULL,
`transaction_name` varchar(128) DEFAULT NULL,
`timeout` int DEFAULT NULL,
`begin_time` bigint DEFAULT NULL,
`application_data` varchar(2000) DEFAULT NULL,
`gmt_create` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`xid`),
KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `branch_table` (
`branch_id` bigint NOT NULL,
`xid` varchar(128) NOT NULL,
`transaction_id` bigint DEFAULT NULL,
`resource_group_id` varchar(32) DEFAULT NULL,
`resource_id` varchar(256) DEFAULT NULL,
`branch_type` varchar(8) DEFAULT NULL,
`status` tinyint DEFAULT NULL,
`client_id` varchar(64) DEFAULT NULL,
`application_data` varchar(2000) DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
PRIMARY KEY (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `lock_table` (
`row_key` varchar(128) NOT NULL,
`xid` varchar(96) DEFAULT NULL,
`transaction_id` bigint DEFAULT NULL,
`branch_id` bigint NOT NULL,
`resource_id` varchar(256) DEFAULT NULL,
`table_name` varchar(32) DEFAULT NULL,
`pk` varchar(36) DEFAULT NULL,
`gmt_create` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`row_key`),
KEY `idx_branch_id` (`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `undo_log` (
`id` bigint NOT NULL AUTO_INCREMENT,
`branch_id` bigint NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
如果启动seata报错缺少文件,看另一篇博文https://blog.csdn.net/weixin_52200307/article/details/111387204
解决上面问题再次启动seata服务,启动成功。
然后打开Eureka查看seata有没有注册进去。
首先都要引入seata的依赖
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-alibaba-seataartifactId>
<version>2.2.0.RELEASEversion>
<exclusions>
<exclusion>
<groupId>io.seatagroupId>
<artifactId>seata-spring-boot-starterartifactId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>io.seatagroupId>
<artifactId>seata-spring-boot-starterartifactId>
<version>1.3.0version>
dependency>
#seata配置
seata:
enabled: true
application-id: order-server #服务名
tx-service-group: my_test_tx_group # 自定义的事务分组名称
enable-auto-data-source-proxy: true # 启用自动数据源代理
use-jdk-proxy: false
service:
vgroup-mapping:
my_test_tx_group: seata-eureka # seata-eureka是tc注册到注册中心的服务名称
enable-degrade: false # 是否启用降级
disable-global-transaction: false # 是否禁用全局事务
config:
type: file # 配置中心为file模式
registry:
type: eureka # 注册中心为eureka
eureka:
weight: 1
service-url: http://localhost:10001/eureka # 注册中心地址
这是我自己遇到的问题,虽然上文也强调了这个问题,但还是会有码农犯跟我一样的错误,启动未报错的则跳过。
启动成功