can not get cluster name in registry config ‘service.vgroupMapping.xx‘, please make sure registry

本文涉及的产品
全局流量管理 GTM,标准版 1个月
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
简介: can not get cluster name in registry config ‘service.vgroupMapping.xx‘, please make sure registry

@[TOC]

一、前言

最近在公司遇到分布式事务嵌套子事务的问题,用的也是seata,于是就准备自己研究一下seata。在搭建项目的过程中,发现一直无法将服务注册到Seata服务中,报错如下:

can not get cluster name in registry config 'service.vgroupMapping.my-tx-group', please make sure registry config correct

从日志来看,每10s疯狂报错:
在这里插入图片描述
我们下面从两种模式:file和nacos进行介绍;

二、配置说明:

seata-server的配置从file.conf文件中取。

1、Seata-server配置

register.conf中 配置的config(配置中心)为type="file"

# 配置中心
# 如果type=file,则从本地file.conf中获取配置参数,并且只有这种情况才从file.conf中加载配置参数
config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "file"

  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
  }
  
  file {
    name = "file.conf"
  }
}

再看file.conf:

service {
  # 事务组名称
  vgroup_mapping.my-tx-group = "seata-server"
  disableGlobalTransaction = false
}

注意:

1、 vgroup_mapping.my-tx-group = "seata-server"为事务组名称,这里的值需要和TC中配置的 service.vgroup-mapping.my-tx-group一致;
2、 my-tx-group自定义名称,可以随便取,seata-server这个值也是一样;
3、事务组的命名不要用下划线'_',可以用'-'因为在seata的高版本中使用underline下划线 将导致service not to be found。

2、seata-client配置

application.yml

# seata 配置
seata:
  # 使用的事务组
  tx-service-group: my-tx-group
  enabled: true

看一些大佬的方式是在resources/目录下增加file.conf配置事务组my-tx-group的值,如下所示:
在这里插入图片描述
在这里插入图片描述
然后运行服务就崩了,大佬不会坑我吧,然后百思不得其解;于是便开始了百度、Google、再到StackOverflow的过程;最后在seata官方的issue 411中发现了一个类似的问题:https://github.com/seata/seata-samples/issues/411

不同的是issue中采用的是nacos作为配置中心,而我采用的是file。
其中提到了一点,必须要在nacos配置一个service.vgroupMapping.my-tx-group=seata-server。
在这里插入图片描述
要不我直接切成nacos做为配置中心吧,但是我的问题还没解决啊,作为一个有专研精神的群体,不能就此放弃呀。

分析一下这个异常,can not get cluster name in registry config,在注册表配置中获取不到群集名称;其在resources/file.conf中配置了呀。我丢,nacos、consul等配置中心本质上只是把application.yml中的配置提到了云端;会不会是要在application.yml中配置的?

去官方看看配置说明:https://seata.io/zh-cn/docs/user/configurations.html

全局搜索 command(Ctrl) + F 搜索service.vgroupMapping
在这里插入图片描述

我们再去application.yml中配置上试试看:

# seata 配置
seata:
  # 使用哪个事务组
  tx-service-group: my-tx-group
  service:
    # 事务组对应的集群民称
    vgroup-mapping.my-tx-group: seata-server
    # seata-server的地址
    grouplist.seata-server: 127.0.0.1:8091
  enabled: true

运行,内心OS(阿门🙏🏻,给我成):
在这里插入图片描述
注册RM成功,再看看seata-server端日志:
在这里插入图片描述
OK,搞定!

三、采用Nacos作为配置中心

在nacos中新增一个dataId为对应事务组的数据即可,可以参考上面提到的seata官方issue411:https://github.com/seata/seata-samples/issues/411
在这里插入图片描述
在这里插入图片描述

四、Seata的其他排坑、实战、源码解析文章

  1. can not get cluster name in registry config ‘service.vgroupMapping.xx‘, please make sure registry问题解决
  2. Seata Failed to get available servers: endpoint format should like ip:port 报错原因/解决方案汇总版(看完本文必解决问题)
  3. Seata json decode exception, Cannot construct instance of java.time.LocalDateTime报错原因/解决方案最全汇总版
  4. 【微服务 31】超细的Spring Cloud 整合Seata实现分布式事务(排坑版)
  5. 【微服务 32】Spring Cloud整合Seata、Nacos实现分布式事务案例(巨细排坑版)【云原生】
  6. 【微服务33】分布式事务Seata源码解析一:在IDEA中启动Seata Server
  7. 【微服务34】分布式事务Seata源码解析二:Seata Server启动时都做了什么
  8. 【微服务35】分布式事务Seata源码解析三:从Spring Boot特性来看Seata Client 启动时都做了什么
  9. 【微服务36】分布式事务Seata源码解析四:图解Seata Client 如何与Seata Server建立连接、通信
  10. 【微服务37】分布式事务Seata源码解析五:@GlobalTransactional如何开启全局事务
  11. 【微服务38】分布式事务Seata源码解析六:全局/分支事务分布式ID如何生成?序列号超了怎么办?时钟回拨问题如何处理?

五、总结

虽说三人行必有我师焉,但听完要实践验证加固记忆。
比如这里我就犯了一个比较低级的错误,SpringBoot项目的配置怎么就从resources目录下的非application.yml、bootstrap.yml中拿了呢?
当我们也不确定谁对谁错的时候,找源码入口,debug源码后答案自见分晓。

我们这里的报错提示是在NettyClientChannelManager类中,我们就进入这个类找一下入口,怎么知道是哪个方法呢?从方法的命名我们来猜,猜了几次还不对,就打断点看。
在这里插入图片描述
这里一共就这几个方法,从命名来看,经验告诉我们应该和Server信息相关,会不会是getAvailServerList()方法呢,试试看看吧,打断点hold住,debug启动:
在这里插入图片描述
下面大家顺着往下走,会发现出问题的地方(这里记得把application.yml中的事务组信息注掉):
在这里插入图片描述

希望我们都会用、善用这种方式解决问题。

回想自己以前负责的一个服务中因为引入配置中心consul,导致项目中的定时任务全部失效,也是通过这种方式找到了问题所在。

相关文章
eggjs 项目报错 Cookie need secret key to sign and encrypt. Please set config.keys first
eggjs 项目报错 Cookie need secret key to sign and encrypt. Please set config.keys first
285 0
eggjs 项目报错 Cookie need secret key to sign and encrypt. Please set config.keys first
|
3月前
|
开发工具 git
*** Please tell me who you are.Run git config --global user.email “you@example.com“ git confi
*** Please tell me who you are.Run git config --global user.email “you@example.com“ git confi
|
3月前
|
PHP
php 使用phpize报错Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize‘ in the top l
php 使用phpize报错Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize‘ in the top l
164 1
|
11月前
|
监控 Dubbo 搜索推荐
No application config found or it‘s not a valid config! Please add <dubbo:application name=“...“ />
No application config found or it‘s not a valid config! Please add <dubbo:application name=“...“ />
1186 1
|
10月前
|
关系型数据库 MySQL Linux
DVWA CentOS Could not connect to the MySQL service. Please check the config file.
DVWA CentOS Could not connect to the MySQL service. Please check the config file.
53 0
|
10月前
|
Java
解决:Config service failed to start in 120 seconds! Please check ./service/apollo-service.log...
解决:Config service failed to start in 120 seconds! Please check ./service/apollo-service.log...
127 0
|
关系型数据库 MySQL 数据库
【报错】DVWA遇到Could not connect to the database service. Please check the config file. Database Error
【报错】DVWA遇到Could not connect to the database service. Please check the config file. Database Error
1029 0
|
Web App开发 JavaScript 安全
Please open the about:config page and disable the "security.fileuri.strict_origin_policy" option
Please open the about:config page and disable the "security.fileuri.strict_origin_policy" option
205 0
Please open the about:config page and disable the "security.fileuri.strict_origin_policy" option
|
资源调度
Registry Config
Registry Config
181 0