Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案。
版本选择
安装
项目中的库需要执行,sql文件路径:https://github.com/seata/seata/tree/develop/script/client
seata服务 需要sql https://github.com/seata/seata/tree/develop/script/server
下载二进制包(windows下载zip、linux下载tar.gz):https://github.com/seata/seata/releases
解压后修改配置
- 修改registry.conf文件
把registry{type = "file"}
改为type = "nacos"
表示使用nacos作为注册中心
把registry{nacos{}}
配置修改为以下配置 配置内容根据自己项目配置同步
nacos {
#服务注册名称(seata项目本身算是个微服务)
application = "seata-server"
#nacos的注册地址
serverAddr = "127.0.0.1:8848"
#服务所在分组
group = "SEATA_GROUP"
#服务的命名空间
namespace = "seata"
cluster = "default"
username = ""
password = ""
}
把config{type="file"}
改为config{type="nacos"}
表示使用nacos读取seata服务的配置
把config{nacos{}}
配置修改为以下配置 配置内容根据自己nacos存储seata配置位置一致
nacos {
serverAddr = "127.0.0.1:8848"
namespace = "seata"
group = "SEATA_GROUP"
username = ""
password = ""
}
seata1.0以上版本只有源码包有config.txt
文件,所以可以下载对应的源码包执行推送配置到nacos的操作
修改seata-1.3.0\script\config-center\config.txt
的配置
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
#这个到时候项目配置yml的时候要一致,最好不改
service.vgroupMapping.my_test_tx_group=default
#这个是事务微服务的启动的服务器地址和端口(我的8081被jenkins占用了所以用8089)
service.default.grouplist=tx.ovozz.com:8099
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=db
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
#对应的数据库地址,到时候要执行sql的库对应
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://tx.ovozz.com:3306/seata?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai
store.db.user=seata
store.db.password=seata
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
store.redis.host=127.0.0.1
store.redis.port=6379
store.redis.maxConn=10
store.redis.minConn=1
store.redis.database=0
store.redis.password=null
store.redis.queryLimit=100
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
执行seata-1.3.0\script\config-center\nacos\nacos-config.sh
对应着上面registry.conf
文件的config{nacos{}}
配置,参数-p端口 -g 分钟 -t 命名空间....
./nacos-config.sh -h tx.ovozz.com -p 8099 -g SEATA_GROUP -t seata
对应的naocs中的配置出现以下配置表示成功
- 修改file.conf存储方式为mysql
vi file.conf 把mode = "file"改为mode = "db"
数据库配置修改
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.jdbc.Driver"
url = "jdbc:mysql://127.0.0.1:3306/seata"
user = "seata"
password = "seata"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
项目配置
application.yml
management:
endpoints:
web:
exposure:
include: '*'
server:
port: 7001
spring:
application:
name: cloud-order-service
cloud:
nacos:
discovery:
server-addr: tx.ovozz.com:8848
namespace: cloud-demo
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://tx.ovozz.com:3306/seata_order?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
username: seata_order
password: seata_order
#分布式事务配置
seata:
application-id: ${spring.application.name}
enabled: true
enable-auto-data-source-proxy: true
#分组名称
tx-service-group: my_test_tx_group
#服务配置
service:
disable-global-transaction: false
vgroup-mapping:
my_test_tx_group: default
grouplist:
default: tx.ocozz.com:8099
#配置中心配置
config:
type: nacos
nacos:
application: seata-server
namespace: seata
serverAddr: tx.ovozz.com:8848
group: SEATA_GROUP
#注册中心配置
registry:
type: nacos
nacos:
application: seata-server
namespace: seata
server-addr: tx.ovozz.com:8848
group: SEATA_GROUP
pom
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
网友评论