目录
1.重点是seata server的配置与启动:
1.1 将seata-server注册到nacos -- 服务注册
1.2 nacos既能做为注册中心,又能做为配置管理中心
1.3 seata-server的事务log存储相关配置:
1.4 启动seata-server
2.seata-server的client端配置:
3.启动微服务并测试
运行seata 实例: https://github.com/seata/seata-samples/tree/master/nacos
按照user guide的步骤,一步一步的完成Seata、Dubbo和Nacos 集成
修改seata-server中的conf目录下的registry.conf文件,选择nacos做为注册中心。
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = ""
password = ""
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
..................................................
还是修改seata-server中的conf目录下的registry.conf文件,选择nacos做为配置中心,集中管理各个微服务的配置信息。
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
#dataId = "seataServer.properties"
}
consul {
serverAddr = "127.0.0.1:8500"
aclToken = ""
}
.............................................
将seata-server的配置导入到nacos
参考文章:https://blog.csdn.net/qq853632587/article/details/111644295 按照里面的步骤,将seata-server配置导入到nacos。下面是成功之后的截图
修改seata-server中的conf目录下的文件file.conf,选择使用db去存储事务log
## transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "db"
## rsa decryption public key
publicKey = ""
## file store property
file {
## store location dir
dir = "sessionStore"
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
maxBranchSessionSize = 16384
# globe session size , if exceeded throws exceptions
maxGlobalSessionSize = 512
# file buffer size , if exceeded allocate new buffer
fileWriteBufferCacheSize = 16384
# when recover batch read size
sessionReloadReadSize = 100
# async, sync
flushDiskMode = async
}
## 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.jdbc.Driver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true"
user = "root"
password = "123456"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
seata-server.bat -h 127.0.0.1 -m db
启动成功之后,seata-server做为一个微服务,根据上面的配置,被注册到nacos。
谁是seata-server的client? 当然是我们的应用程序,我们的应用程序中依赖这个jar包 -- seata-all
io.seata
seata-all
1.3.0
client端也是需要进行配置的,具体的需要在file.conf和registry.conf文件中进行配置
NOTE: serverAddr和namespace与Server端一致,clusterName与Server端cluster一致
需要将seata的java客户端的版本换成1.3.0,不然会报错儿,具体解决问题的过程,请参考文章:https://blog.csdn.net/wdquan19851029/article/details/116751027
io.seata
seata-all
1.3.0
启动完成可在 Nacos 控制台服务列表 看到启动完成的三个 provider
最后,启动 DubboBusinessTester 进行测试
订单创建完成:
货物库存由100变成98:
资金账户的钱由999变成599: