分布式微服务架构下的全局数据一致性问题 [即: 分布式事务问题]
一句话: Seata 是一款开源的分布式事务解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务
第一步、将 seata-server-0.9.0.zip 解压到 指定目录 ,修改 conf\file.conf文件
vgroup_mapping.my_test_tx_group = "xjz_order_tx_group"
mode = "db"
url = "jdbc:mysql://127.0.0.1:3308/seata" #5.7的端口我自己配的3308、默认3306
user = "root
password = "xjz"
第二步、在mysql5.7 创建 seata数据库
CREATE DATABASE seata
USE seat
-- the table to store GlobalSession data
drop table if exists `global_table`;
CREATE TABLE `global_table` (
`xid` VARCHAR(128) NOT NULL,
`transaction_id` BIGINT,
`status` TINYINT NOT NULL,
`application_id` VARCHAR(32),
`transaction_service_group` VARCHAR(32),
`transaction_name` VARCHAR(128),
`timeout` INT,
`begin_time` BIGINT,
`application_data` VARCHAR(2000),
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`xid`),
KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
KEY `idx_transaction_id` (`transaction_id`)
);
-- the table to store BranchSession data
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
`branch_id` BIGINT NOT NULL,
`xid` VARCHAR(128) NOT NULL,
`transaction_id` BIGINT ,
`resource_group_id` VARCHAR(32),
`resource_id` VARCHAR(256) ,
`lock_key` VARCHAR(128) ,
`branch_type` VARCHAR(8) ,
`status` TINYINT,
`client_id` VARCHAR(64),
`application_data` VARCHAR(2000),
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`branch_id`),
KEY `idx_xid` (`xid`)
);
-- the table to store lock data
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table` (
`row_key` VARCHAR(128) NOT NULL,
`xid` VARCHAR(96),
`transaction_id` LONG ,
`branch_id` LONG,
`resource_id` VARCHAR(256) ,
`table_name` VARCHAR(32) ,
`pk` VARCHAR(36) ,
`gmt_create` DATETIME ,
`gmt_modified` DATETIME,
PRIMARY KEY(`row_key`)
);
第三步、修改 seata 的 \conf\registry.conf 配置注册中心 nacos server
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
# type = "file"
type = "nacos"
nacos {
#serverAddr = "localhost"
serverAddr = "localhost:8848" #nacos端口号:8848
namespace = ""
cluster = "default"
}
第四步、启动 seata–> bin-- > seata-server.bat
启动前切记打开 nacos server,否则启动自动闪退!
第五步、登录 Nacos Server,查看 Seata Server 是否注册成功