记录一下这个有点坑的问题:
no available service ‘null’ found, please make sure registry config correct
springboot 2.2.9
springcloud alibaba 2.2.1
seata 1.3
nacos 1.3.2
按照最新的seata文档搭建好后一直报这个错,根据网上的解决方案检查注册中心配置没问题
registry.conf
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "server-seata"
serverAddr = "xxx:8848"
group = "DEFAULT_GROUP"
namespace = "cloud-platform-dev"
cluster = "default"
username = "nacos"
password = "nacos"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "xxxx:8848"
group = "DEFAULT_GROUP"
namespace = "cloud-platform-dev"
username = "nacos"
password = "nacos"
}
}
file.conf
store {
## store mode: file、db、redis
mode = "db"
## 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"
url = "jdbc:mysql://xxx:3308/seata"
user = "root"
password = "xxxx"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
客户端配置service-user-dev.yml:
seata:
application-id: ${spring.application.name}
enabled: true
tx-service-group: ${spring.application.name}-group
enable-auto-data-source-proxy: true
config:
type: nacos
nacos:
namespace: ${spring.cloud.nacos.config.namespace}
serverAddr: xxxx:8848
group: DEFAULT_GROUP
userName: "nacos"
password: "nacos"
registry:
type: nacos
nacos:
application: server-seata
serverAddr: xxxx:8848
group: DEFAULT_GROUP
namespace: ${spring.cloud.nacos.config.namespace}
userName: "nacos"
password: "nacos"
cluster: default
检查了service.vgroupMapping 没有问题,网上的解决方案基本上都试过了,问题没得到解决,于是我决定看看源码,通过源码我发现seata通过下面get请求从nacos上面获取配置:
http://127.0.0.1:8848/nacos/v1/ns/instance/list?app=service-user&healthyOnly=false&namespaceId=cloud-platform-dev&clientIP=192.168.0.106&serviceName=DEFAULT_GROUP%40%40server-seata&udpPort=62880&accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTU5OTc2MTU4NX0.PYtcLgh2C_X5J9-ZGpVZsmn1AmL4vVg8rWVR54zHtmI&encoding=UTF-8&clusters=null
大家注意到没有clusters = null,拿不到hosts,我们的明明是default,然后我手动测试
然后我手动改default试试,居然就拿到了,在这里我怀疑是我们配置的问题。
http://127.0.0.1:8848/nacos/v1/ns/instance/list?app=service-user&healthyOnly=false&namespaceId=cloud-platform-dev&clientIP=192.168.0.106&serviceName=DEFAULT_GROUP%40%40server-seata&udpPort=62880&accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTU5OTc2MTU4NX0.PYtcLgh2C_X5J9-ZGpVZsmn1AmL4vVg8rWVR54zHtmI&encoding=UTF-8&clusters=default
请求一下我对应的配置试试:
http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=service.vgroupMapping.my_test_tx_group&group=DEFAULT_GROUP&tenant=cloud-platform-dev&accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTU5OTc2MTU4Mn0.vASaGpQx0tlxSxzre6s9A15q9lAFvQH2lv4uCzdCRE4
返回的:
这怎么可能不存在,我又没瞎。
然后我请求我另外的配置:
能拿到配置,这里没问题,然后我恍然大悟,是不是我的nacos 没有刷新,于是我重启一下nacos,再次请求。
能拿到值了,然后我重新启动项目,果然就不报错了。
看到这里我想的是,在使用新技术的同时一定要养成自己解决问题的能力。加油,骚年们,老板叫我去加班了。