Seata参考资料和下载
Seata官网: Apache Seata
Seata中文开发文档: Seata 是什么? | Apache Seata
Seata下载地址:
这里提供一个最新版的
seata-server-2.0.0.zip官方版下载丨最新版下载丨绿色版下载丨APP下载-123云盘
Seata的配置
第一步解压Seata
第二步 配置seata根目录下的conf下的application.yml
下面是application.yml里面的配置
# Copyright 1999-2019 Seata.io Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
server:
port: 7091 # seata 的端口号
spring:
application:
name: seata-server # seata 注册进入到nacos里面的名字
logging:
config: classpath:logback-spring.xml
file:
path: ${log.home:${user.home}/logs/seata}
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash
console:
user:
username: seata
password: seata
seata:
config:
# support: nacos, consul, apollo, zk, etcd3
type: nacos
nacos:
server-addr: 127.0.0.1:8848
namespace: b75ba2b8-edbd-4f06-86d5-9e805933f6e2
username:
password:
group: SEATA_GROUP
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: nacos # 注册到nacos的配置
nacos:
application: seata-server # seata服务的名字
server-addr: 127.0.0.1:8848 # nacos的地址
group: SEATA_GROUP # seata 服务的分组 默认 SEATA_GROUP
namespace: # 指定seata在nacos中哪个命名空间中
cluster: default
username: # nacos的登录账号 没有就为空
password: # nacos的登录密码 没有就为空
store:
# support: file 、 db 、 redis 、 raft
mode: db # 模式改为db
session:
mode: db # 模式改为db
lock:
mode: db # 模式改为db
db: # 这里是配置数据库的
datasource: druid
db-type: mysql # 数据库类型
driver-class-name: com.mysql.jdbc.Driver # mysql驱动
url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true #数据库地址
user: root #数据库连接账号
password: root # 数据库连接地址
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 5000
# server:
# service-port: 8091 #If not configured, the default is '${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**
第三步配置seata根目录下的script下的config-center下的config.txt
第四步在自己的数据库中简历seata表
第五步执行一下sql语句
-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `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_status_gmt_modified` (`status` , `gmt_modified`),
KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
`branch_id` BIGINT NOT NULL,
`xid` VARCHAR(128) NOT NULL,
`transaction_id` BIGINT,
`resource_group_id` VARCHAR(32),
`resource_id` VARCHAR(256),
`branch_type` VARCHAR(8),
`status` TINYINT,
`client_id` VARCHAR(64),
`application_data` VARCHAR(2000),
`gmt_create` DATETIME(6),
`gmt_modified` DATETIME(6),
PRIMARY KEY (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
`row_key` VARCHAR(128) NOT NULL,
`xid` VARCHAR(128),
`transaction_id` BIGINT,
`branch_id` BIGINT NOT NULL,
`resource_id` VARCHAR(256),
`table_name` VARCHAR(32),
`pk` VARCHAR(36),
`status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`row_key`),
KEY `idx_status` (`status`),
KEY `idx_branch_id` (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `distributed_lock`
(
`lock_key` CHAR(20) NOT NULL,
`lock_value` VARCHAR(20) NOT NULL,
`expire` BIGINT,
primary key (`lock_key`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);
如果是下图就算成功了
第六步启动
seata的一些说明
启动seata之前需要先启动nacos
启动seata (seata===》bin ===》双击seata-server.bat文件)
访问http://127.0.0.1:7091/#/login
账号:seata
密码 : seata
登录成功之后
如何在项目中使用seata
第一步导入jar包
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2023.0.1.2</version>
</dependency>
第二步配置自己项目中application.yml文件
seata: registry: # 配置 seata注册中心 type: nacos nacos: server-addr: localhost:8848 #nacos中 seata服务地址 group: SEATA_GROUP # seata 在nacos中的分组 namespace: "b75ba2b8-edbd-4f06-86d5-9e805933f6e2" #seata服务 在nacos中 的命名空间地址 application: seata-server # seata的应用服务名称 tx-service-group: default_tx_group # tx事务分组 service: # 配置分组信息 vgroup-mapping: default_tx_group: default data-source-proxy-mode: AT # 配置seata的代理模式