Seata的简单使用
本文只介绍Seata的简单使用,没有涉及其原理.
1.在本地搭建一个TC服务(事务协调者).
1.1 下载seata的安装包
往下滑滑,找到你想要的版本和格式下载即可.我这里使用的是seata-server-1.1.0.zip,解压即可使用.
1.2 配置
打开解压目录下的conf/registry.conf文件如下
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
# 可以把seata-server理解为一个服务,它需要把自己注册到某个注册中心上去,方便使用seata的服务来找到自己
#在这里就是指定注册中心的类型,由于我们项目用的是eureka,所以这里我选择eureka,即这一堆配置就下面一个eureka生效了
#这里默认的是file,即文件,选了文件就可以不用搭注册中心,直接从文件里读取服务列表
#复制之后一定要改一改
type = "eureka"
nacos {
serverAddr = "localhost"
namespace = ""
cluster = "default"
}
eureka { #"只有我生效啦"
serviceUrl = "http://localhost:10086/eureka" #eureka地址
application = "seata_tc_server"#在eureka里显示的名字
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
etcd3 {
cluster = "default"
serverAddr = "http://localhost:2379"
}
sofa {
serverAddr = "127.0.0.1:9603"
application = "default"
region = "DEFAULT_ZONE"
datacenter = "DefaultDataCenter"
cluster = "default"
group = "SEATA_GROUP"
addressWaitTime = "3000"
}
file {
name = "file.conf"
}
}
config {
#在这里选择配置中心,这里我们选择file
# file、nacos 、apollo、zk、consul、etcd3
type = "file"
nacos {
serverAddr = "localhost"
namespace = ""
group = "SEATA_GROUP"
}
consul {
serverAddr = "127.0.0.1:8500"
}
apollo {
app.id = "seata-server"
apollo.meta = "http://192.168.1.204:8801"
namespace = "application"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
#由于选择了file,所以这里生效了