学习seata,配置了从nacos读取配置
配置结构
nacos配置对应的service.vgroupMapping
registry.conf
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "localhost:8848"
namespace = ""
username = ""
password = ""
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3、springCloudConfig
type = "nacos"
nacos {
serverAddr = "localhost:8848"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
file {
name = "file.conf"
}
}
seata.conf
这个配置很重要,标识当前应用分布式事务
client {
application.id = health-base
transaction.service.group = health-base-group
}
启动项目,报错:
Exception in thread "main" io.seata.common.exception.FrameworkException: No available service
at io.seata.core.rpc.netty.AbstractRpcRemotingClient.loadBalance(AbstractRpcRemotingClient.java:194)
at io.seata.core.rpc.netty.AbstractRpcRemotingClient.sendMsgWithResponse(AbstractRpcRemotingClient.java:140)
at io.seata.core.rpc.netty.AbstractRpcRemotingClient.sendMsgWithResponse(AbstractRpcRemotingClient.java:148)
at io.seata.tm.DefaultTransactionManager.syncCall(DefaultTransactionManager.java:95)
at io.seata.tm.DefaultTransactionManager.begin(DefaultTransactionManager.java:53)
at io.seata.tm.api.DefaultGlobalTransaction.begin(DefaultGlobalTransaction.java:105)
at io.seata.tm.api.DefaultGlobalTransaction.begin(DefaultGlobalTransaction.java:87)
at io.seata.tm.api.DefaultGlobalTransaction.begin(DefaultGlobalTransaction.java:82)
经过检查,配置都正确,发现我的seata-server版本是1.2.0的,但是seata-all的版本为1.1.0
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.1.0</version>
</dependency>
修改为对应的版本即可(或者更高的版本,我修改的是1.3.0)
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.2.0</version>
</dependency>
后记
使用seata,还是要弄清楚各项配置的作用,包括服务端的配置,客户端的配置,数据从nacos读取或者从其他服务端读取,是一个什么样的方式.