seata-1.4.0安装及在springcloud中使用详解
作者:橙子VC 发布时间:2023-02-21 00:49:21
seata-1.4.0安装及使用
1、简介
Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案。
详见官方文档:https://seata.io/zh-cn/docs/overview/what-is-seata.html
网上的多是0.9.0版本的安装方式,这里记录安装seata-1.4.0版本的方式,在win10环境下安装,centos7与此相同。
下载
需要下载seata-1.4.0.zip 和 seata-server-1.4.0.zip两个安装包
下载地址:https://github.com/seata/seata/releases
2.1、seata-server-1.4.0
安装配置
解压压缩包,修改conf内的配置文件
2.1.1、registry.conf修改:
我使用的nacos作为配置中心和注册中心,使用将配置文件改为nacos
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
}
2.1.2、file.conf修改:
修改数据库地址,注意mysql5/mysql8驱动不同
store {
## store mode: file、db、redis
mode = "db"
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.cj.jdbc.Driver"
url = "jdbc:mysql://127.0.0.1:3307/seata?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true"
user = "root"
password = "123456"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
2.1.3、创建数据库
创建数据库seata,并建立下面三张表(branch_table, global_table, lock_table),创建undo_log表放到业务库中
-- 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`)
);
-- the table to store seata xid data
-- 0.7.0+ add context
-- you must to init this sql for you business databese. the seata server not need it.
-- 此脚本必须初始化在你当前的业务数据库中,用于AT 模式XID记录。与server端无关(注:业务数据库)
-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
drop table `undo_log`;
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
2.1.4、启动
seata-1.4\bin目录下:双击 seata-server.bat
nacos中查看服务是否注册成功
2.2 seata-1.4.0.
配置
解压安装包,并修改配置
2.2.3 修改config.txt
路径:script\config-center
修改service.vgroupMapping和数据库地址
service.vgroupMapping.system-server-group=default
service.vgroupMapping.product-server-group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://192.168.111.130:3307/seata?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true
store.db.user=root
store.db.password=123456
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
注:
service.vgroupMapping.system-server-group=default
service.vgroupMapping.product-server-group=default
#system-server-group、product-server-group 与项目模块中yml配置的seata.tx-service-group内容相同
2.2.3 启动nacos-config.sh,
将配置注入到nacos中
1、在seata-server-1.4.0\script\config-center\nacos目录下,右键 Git Bash Here
2、输入命令:
sh nacos-config.sh -h 127.0.0.1 -p 8848 -g SEATA_GROUP -u nacos -w nacos
返回成功
2.2.3、nacos中查看配置
在nacos配置列表中找到config.txt配置的vgroupMapping,即说明注入成功

3.4、启动服务:
控制台输出:
3.5、测试
调用方控制台打印
被调用方异常控制台打印:
来源:https://blog.csdn.net/weixin_37698336/article/details/111170580


猜你喜欢
- 开发过程, 我们习惯把数据源配置, 项目常量, 日志配置等基础数据配置写到一个个单独的的文件中. 如jdbc.properties等各种.格
- 本文主要介绍了c# 使用线程对串口serialPort进行收发数据,分享给大家,具体如下:一共写了四种方法,窗体界面都是一样的:方法一:us
- 1、实现循环队列【OJ链接】循环队列一般通过数组实现。我们需要解决几个问题。(1)数组下标实现循环a、下标最后再往后(offset 小于 a
- SqlMapConfig.xml的约束,也就是Mybatis主配置文件的约束<?xml version="1.0"
- 目录1、下列四项中,不属于数据库系统的特点的是( )2、一个学生可以同时借阅多本书,一本书只能由一个学生借阅,学生和图书之间为 ( ) 联系
- 题目:使用struts2自定义 * ,完成用户登陆才能访问权限的实现在session中存放user变量表示用户登陆,若user为空则用户没有
- 本文演示android中图片加载到内存首先设计界面:代码如下:<LinearLayout xmlns:android="ht
- 获取Spring中的bean有很多种方式,再次总结一下:第一种:在初始化时保存ApplicationContext对象Application
- spring.activemq.pool.enabled=false时,每发送一条数据都需要创建一个连接,这样会出现频繁创建和销毁连接的场景
- 分转元private String fenToYuan(String amount){ NumberFormat format
- 一键格式化代碼: Ctrl+Alt+L注意:如果按Ctrl+Shift+F在win10上会出现字体的简繁转换,再重复按键一次就可以转换回来a
- 注解实现自动装配@Autowire注解@Autowire注解,自动装配通过类型,名字如果Autowire不能唯一自动装配上属性,则需要通过@
- 一、前言:垃圾回收:在未来的JDK中可能G1会为ZGC所取代先问自己几个问题:什么是垃圾?垃圾就是堆内存中(范指)没有任何指针指向的对象实体
- hashCode()和equals()方法可以说是Java完全面向对象的一大特色.它为我们的编程提供便利的同时也带来了很多危险.这篇文章我们
- 最近项目需要,需要做一个BMI指数的指示条,先上效果图: BMI指数从18到35,然后上面指示条的颜色会随着偏移量的变化而改变,数字显示当前
- 前言: 之前安装了Ubuntu 18.04,结果在安装Codeblocks / VScode还是安装gcc,c/c++的时候出现了一堆错误(
- 我在 android里面 使用html5的 localStorage 为什么存不进去也读不出来呀?网上搜了好多都没效果mainWebView
- 前言我们经常会被问到这么一个问题:SpringBoot相对于spring有哪些优势呢?其中有一条答案就是SpringBoot自动注入。那么自
- 关于刮刮卡的实现效果不需要做太多解释,特别是在电商APP中,每当做活动的时候都会有它的身影存在,趁着美好周末,来实现下这个效果,也算是对零
- 前言:前两天做项目的时候,想提高一下插入表的性能优化,因为是两张表,先插旧的表,紧接着插新的表,一万多条数据就有点慢了后面就想到