seata2.0,报service.vgroupMapping.default_tx_group configuration item is required错误


seata官网

自配seata参考文档位置:

  • 用户文档 — 事务分组
  • 运维指南 — 部署 — 新人文档
  • 运维指南 — 部署 — 高可用部署

问题

  我的报错内容是:原因二和原因四都触发过。

完整报错信息

ERROR 11940 --- [xxx] [eoutChecker_2_1] i.s.c.r.netty.NettyClientChannelManager  : Failed to get available servers: service
.vgroupMapping.default_tx_group configuration item is required

原因一

  未配置事务分组。

原因二

  后端服务中配置seata的nacos配置 namespace 为public就会报错,需要使用空字符串或者空。

注:后端服务配置中的nacos的命名空间可以使用public,seata服务配置中的nacos的命名空间可以使用public,后端服务中配置seata中的nacos的命名空间需要使用空。

原因三

  seata的nacos配置中心使用group:SEATA_GROUP,seata的nacos注册中心使用group:DEFAULT_GROUP时,后端服务nacos引入的seata配置文件group为SEATA_GROUP就会报错,引入group为空就不会报错。

原因四

  缓存问题。

  是哪里有缓存呢?
    是后端服务配置的seata配置有缓存。
  缓存会导致什么呢?
    缓存会导致出现未知错误,或者已更改配置信息,重启服务后,配置未生效仍然报错。
  缓存问题怎么处理呢 ?
    修改后端服务配置的seata.service.vgroup-mapping.default_tx_group的值,重启服务,重启完再改回去,再次重启服务,就可以解决(通过修改已缓存配置达到刷新缓存的目的)。

注:配置在nacos注册中心,还是配置在后端服务,更改上述配置文件的位置后重启服务都可以达到解决缓存的目的。


配置参考

版本信息

  • jdk 22.0.1
  • springboot 3.2.5
  • springcloud 2023.0.1
  • springcloud alibaba 2023.0.1.0
    • seata 2.0
  • mysql 8.0.12

seata服务配置文件

注:写的附带有默认配置,可不看

文件位置

  seata-server-2.0.0/conf/application.yml

注:官方自带全配置文件位置:seata-server-2.0.0/conf/application.example.yml

配置内容

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${log.home:${user.home}/logs/seata}
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata
seata:
  #配置中心
  config:
    type: nacos
    #nacos配置中心配置信息
    nacos:
      server-addr: 127.0.0.1:8848
      namespace: public
      group: DEFAULT_GROUP
      context-path:
      #此项可以不加
      file-extension: yaml
      #data-id: seata.properties
      #指向nacos配置中心的seata服务的配置文件(seata服务的配置文件)
      data-id: seata.yaml
  #注册中心
  registry:
    type: nacos
    #nacos注册中心配置信息
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      namespace: public
      group: DEFAULT_GROUP
      #事务分组需要对应内容
      cluster: default
      context-path:
  store:
    mode: db
    lock:
      mode: db
    session:
      mode: db
  #数据库连接
  db:
    datasource: druid
    db-type: mysql
    #mysql5.x:driverClassName: com.mysql.jdbc.Driver
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: > 
      jdbc:mysql://localhost:3306/seata?
      useSSL=false&
      useUnicode=true&
      characterEncoding=utf8&
      serverTimezone=GMT%2B8&
      allowPublicKeyRetrieval=true&
      rewriteBatchedStatements=true
    user: root
    password: root
    min-conn: 10
    max-conn: 100
    global-table: global_table
    branch-table: branch_table
    lock-table: lock_table
    distributed-lock-table: distributed_lock
    query-limit: 1000
    max-wait: 5000
  #  server:
  #    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**

seata配置文件

说明:
  此配置文件包含 seata服务的配置文件seata相关的配置文件 ,可以拆分开。

文件位置

  nacos配置中心/seata.yaml

注:官方自带 seata服务的配置文件 全配置文件位置:seata-server-2.0.0/script/config-center/config.txt

nacos配置中心新建seata.yaml配置文件

访问:http://localhost:8848/nacos/
配置管理 — 配置列表 — 创建配置
  命名空间:public
  Data ID:seata.yaml
  Group:DEFAULT_GROUP
  配置格式:yaml
  配置内容:

配置内容

##seata配置(seata相关的配置文件),配置在服务消费方 & 服务提供方。端口8091,依赖于mysql服务、nacos服务。客户端访问地址:http://127.0.0.1:7091/

seata:
  #是否开启springboot自动装配seata,默认为true开启
  #enabled: true
  #配置事务分组,在v1.5之后默认值为default_tx_group
  tx-service-group: default_tx_group
  #数据源自动代理
  #enable-auto-data-source-proxy: true
  #分布式事务模式
  #data-source-proxy-mode: AT
  service:
    #开启全局事务,默认为false开启
    #disable-global-transaction: false
    #可以不需要
    vgroup-mapping:
      default_tx_group: default
  #client:
    #tm:
      #default-global-transaction-timeout: 60000
  #配置中心
  config:
    type: nacos
    nacos:
      #server-addr: 127.0.0.1:8848
      server-addr: ${nacos.server-addr}
      namespace: ${nacos.namespace}
      group: ${nacos.group}
  #配置seata的注册中心,告诉seata client怎么去访问seata server(TC)
  registry:
    type: nacos
    nacos:
      #seata server所在的nacos地址
      #server-addr: 127.0.0.1:8848
      server-addr: ${nacos.server-addr}
      namespace: ${nacos.namespace}
      #seata servers所在的组,默认是SEATA_GROUP,没有修改可以不配
      group: ${nacos.group}
      #seata server的服务名seata-server,没有修改可以不配
      application: seata-server
      #context-path: 
      #username:
      #password:


##seata服务配置(seata服务的配置文件)

#事务分组
#主要用于解决异地机房停电容错,可以快速切换事务分组。
#default_tx_group:配置事务的分组名称,可以自定义
#default:必须等于application.yml中 seata.registry.nacos.cluster=default
service:
  vgroupMapping:
    default_tx_group: default
  #开启全局事务,默认为false开启
  #disableGlobalTransaction: false

store:
  mode: db
  lock:
    mode: db
  session:
    mode: db
  #数据库连接
  db:
    dbType: mysql
    datasource: druid
    #mysql5.x:driverClassName: com.mysql.jdbc.Driver
    driverClassName: com.mysql.cj.jdbc.Driver
    #mysql5.x
    #url: jdbc:mysql://localhost:3306/seata?useUnicode=true&rewriteBatchedStatements=true
    #mysql8.x
    url: >
      jdbc:mysql://127.0.0.1:3306/seata?
      useSSL=false&
      useUnicode=true&
      characterEncoding=utf8&
      serverTimezone=GMT%2B8&
      allowPublicKeyRetrieval=true&
      rewriteBatchedStatements=true
    user: root
    password: root
    minConn: 5
    maxConn: 30
    globalTable: global_table
    branchTable: branch_table
    distributedLockTable: distributed_lock
    #查询条数
    queryLimit: 100
    lockTable: lock_table
    #最大等待时间
    maxWait: 5000

client:
  undo:
    #事务日志表,默认为undo_log
    logoTable: undo_log
server:
  undo:
    #undo保留天数,默认7天,log_status=1的undo、未正常清理的undo
    logSaveDays: 7

依赖引入

注:使用的start方式,seata.io方式有些操作好像需要手动实现。

<!-- SpringCloud Alibaba 微服务的版本管理 -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2023.0.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId>
        </exclusion>
    </exclusions>
    <type>pom</type>
    <scope>import</scope>
</dependency>

<dependency>
    <groupId>io.seata</groupId>
    <artifactId>seata-spring-boot-starter</artifactId>
    <version>2.0.0</version>
</dependency>

或者

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2023.0.1.0</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>

后端服务配置文件

文件位置

  src/resources/bootstrap.yml

配置内容

#nacos配置,配置在服务消费方 & 服务提供方。端口8848,nacos配置中心依赖于mysql服务。访问地址:http://localhost:8848/nacos/

#自定义nacos配置信息
nacos:
  #nacos服务端地址
  server-addr: 127.0.0.1:8848
  #环境,默认为:public
  namespace: ""
  #项目,默认为:DEFAULT_GROUP
  group: DEFAULT_GROUP

spring:
#  datasource:
#    dynamic:
#      seata: true
  cloud:
    nacos:
      config:
        server-addr: ${nacos.server-addr}
        namespace: ${nacos.namespace}
        group: ${nacos.group}
        #Nacos客户端默认是Properties的文件扩展名,一旦修改成了非Properties格式,则必须通过file-extension进行设置
        #设置读取的配置中心文件扩展名,默认为properties
        file-extension: yaml
        #设置为false时nacos客户端将无法感知配置的变化,默认为true
        refresh-enabled: true
        shared-configs:
          #配置中心的mysql配置引入,不使用此方式可忽略
          #- data-id: mysql.yaml
          #  group: ${nacos.group}
          #  refresh: true
          #配置中心的seata配置引入,需要引入的是后端服务seata配置的部分。(seata相关的配置文件)
          - data-id: seata.yaml
            group: ${nacos.group}
            #配置中心的配置自动刷新,默认为true。
            refresh: true
      discovery:
        server-addr: ${nacos.server-addr}
        namespace: ${nacos.namespace}
        group: ${nacos.group}
#        username: #用户名
#        password: #密码

logging:
  level:
    #打印nacos日志
    com.alibaba.cloud.nacos.configdata: debug

mysql数据库内容

1、需要自建seata数据库

 创建seata库:
   数据库名:seata
   字符集:utf8mb4
   排序规则:utf8mb4_0900_ai_ci

 seata库
   global_table:存储全局事务信息
   branch_table:存储分支信息(事务参与者信息)
   lock_table:存储全局锁
   distributed_lock:存储分布式锁

注:seata数据库官方表sql位置:seata-server-2.0.0/script/server/db/mysql.sql

2、在需要使用seata的服务的数据库中,每个数据库新建 undo_log

-- 参考sql
-- 时间内容使用 datetime 或者 timestamp 字段 
CREATE TABLE `undo_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `context` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` timestamp NOT NULL,
  `log_modified` timestamp NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ux_undo_log`(`xid` ASC, `branch_id` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

seata的使用

  @GlobalTransactional


总结

  报错的原因,要么就是没有配置事务分组,要么就是配置的事务分组无法拿到。(◕ᴗ◕✿)

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 在注册表配置中无法获取集群名称 'service.vgroupMapping.default_tx_group',请确保注册表配置正确。\[1\] \[2\] \[3\] #### 引用[.reference_title] - *1* [can not get cluster name in registry config ‘service.vgroupMapping.xx‘, please make sure registry](https://blog.csdn.net/Saintmm/article/details/121725763)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [can not get cluster name in registry config ‘service.vgroupMapping.xxx-seata-service-group](https://blog.csdn.net/zxy144/article/details/122560661)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [seata错:can not get cluster name in registry config service.vgroupMapping.xxx](https://blog.csdn.net/virtual_users/article/details/130423120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值