seata-1.4.0安裝及在springcloud中使用詳解
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環(huán)境下安裝,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修改:
修改數(shù)據(jù)庫地址,注意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、創(chuàng)建數(shù)據(jù)庫
創(chuàng)建數(shù)據(jù)庫seata,并建立下面三張表(branch_table, global_table, lock_table),創(chuàng)建undo_log表放到業(yè)務庫中 -- 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. -- 此腳本必須初始化在你當前的業(yè)務數(shù)據(jù)庫中,用于AT 模式XID記錄。與server端無關(注:業(yè)務數(shù)據(jù)庫) -- 注意此處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和數(shù)據(jù)庫地址 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、測試
調用方控制臺打印

被調用方異??刂婆_打?。?/p>

到此這篇關于seata-1.4.0安裝及在springcloud中使用的文章就介紹到這了,更多相關springcloud seata安裝使用內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Spring Boot + Mybatis-Plus實現(xiàn)多數(shù)據(jù)源的方法
這篇文章主要介紹了Spring Boot + Mybatis-Plus實現(xiàn)多數(shù)據(jù)源的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11
macOS中搭建Java8開發(fā)環(huán)境(基于Intel?x86?64-bit)
這篇文章主要介紹了macOS中搭建Java8開發(fā)環(huán)境(基于Intel?x86?64-bit)?的相關資料,需要的朋友可以參考下2022-12-12
SpringBoot實現(xiàn)的Mongodb管理工具使用解析
這篇文章主要介紹了SpringBoot實現(xiàn)的Mongodb管理工具使用解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-09-09
SpringBoot開發(fā)詳解之Controller接收參數(shù)及參數(shù)校驗
數(shù)據(jù)校驗是為了使系統(tǒng)更完整,數(shù)據(jù)更精確,同時也有利于維護數(shù)據(jù)的安全性,下面這篇文章主要給大家介紹了關于SpringBoot開發(fā)詳解之Controller接收參數(shù)及參數(shù)校驗的相關資料,需要的朋友可以參考下2022-03-03
Java線程池的幾種實現(xiàn)方法和區(qū)別介紹實例詳解
本篇文章主要介紹了Java線程池的幾種實現(xiàn)方法和區(qū)別,需要的朋友可以參考2017-04-04

