分布式事务-SEATA

分布式事务简介直接引用别人的文章吧,这样的文章太多了 https://www.codenong.com/cs105728924/
 
 
  1. 官网下载源码和安装文件
  2. 修改配置文件file.conf
  3. 服务端部署
  4. 客户端应用集成
seata源码启动-版本1.2.0:
  1. 官网下载源码,并解压
  2. 使用idea打开,根目录执行mvn install -Dmaven.test.skip=true,则所有项目都会自动打包
  3. 注意:maven的版本需要升级到3.6以后
  4. 启动server项目(服务端)- 这时候查看配置文件file.conf(模板file.conf.example)可以看到是以file模式启动的
    1. 修改数据模式存放为db的-数据库为mysql
 
一、seata-file形式存储事务信息:
配置文件:\seata-1.2.0\server\src\main\resources\file.conf
store.mode=file
 
 
二、seata-db形式存储事务信息 :
配置文件:\seata-1.2.0\server\src\main\resources\file.conf
store.mode=db
db.url=服务端事务数据存储数据库,及用户名密码
globalTable、branchTable、lockTable:事务存储信息的表名称
创建对应的数据库以及其中创建对应的表,脚本地址:https://github.com/seata/seata/tree/develop/script/server
 

三、使用seata-配置文件存放到配置中心-即不用file.conf:
 
  1. 需要配置中心则修改配置文件:\seata-1.2.0\server\src\main\resources\registry.conf
  2. register.type=nacos
  3. 配置nacos对应的服务配置
  4. 将对应配置放到配置中心的目录推荐sh脚本:https://github.com/seata/seata/edit/develop/script/config-center/config.txt(可以先把db对应的配置上传)
  5. 执行脚本将配置信息上传到nacos上:seata-1.2.0\script\config-center\nacos\nacos-config.sh(注意如果需要namespace则新建一个namespace,并修改脚本的tenantId信息)
 
 客户端和服务端的重要配置,具体格式可以按照config.txt中的参照:

server
client
store.mode: file,db
config.type: file、nacos 、apollo、zk、
consul、etcd3、custom
#only db:
#only file:
store.db.driverClassName
service.default.grouplist
(seata服务地址127.0.0.1:8091)
store.db.url
#All:
store.db.user
service.vgroupMapping.my_test_tx_group
(my_test_tx_group是事务组名称)
store.db.password
service.disableGlobalTransaction
 
 
 
客户端file.conf实例
service {
  #vgroup->rgroup
  vgroupMapping.my_test_tx_group = "default"
  #only support single node
  default.grouplist = "127.0.0.1:8091"
  #degrade current not support
  enableDegrade = false
  #disable
  disable = false
}

 

四、集成实例 - 注意修改file.conf中seata的地址
  1.     每个客户端必须添加UNDOLOG表,来对全局事务支持脚本地址:http://seata.io/zh-cn/docs/user/quickstart.html
  2.     官方测试实例地址:https://github.com/seata/seata-samples
  3.     简单的springboot实例: seata-samples\springboot-mybatis
  4.     原生seata项目:seata-samples\api
  5.  spring-cloud-alibaba集成例子: seata-samples\spring-cloud-alibaba-samples
 
 
 
 
 
posted @ 2020-12-17 17:50  码来  阅读(556)  评论(0编辑  收藏  举报