2021-04-22

本文详细介绍了如何在Spring Boot 2.3.6应用中集成Spring Cloud Hoxton.SR9、Spring Cloud Alibaba 2.2.3和Seata 1.4.0版本,涉及Nacos配置中心的事务分组设置,以及如何在application.yml中配置数据源和Seata。重点讲解了Seata的配置和与Nacos的交互,适用于Spring Cloud微服务场景。
摘要由CSDN通过智能技术生成

springclould seata nacos feign集成

版本:
<springboot.version>2.3.6.RELEASE</springboot.version>
<springclould.version>Hoxton.SR9</springclould.version>
<springcloud.alibaba.version>2.2.3.RELEASE</springcloud.alibaba.version>
<seata.version>1.4.0</seata.version>

服务配置:application.yml

server:
  port: 8081

spring:
  datasource:
    username: root
    password: yhj19950715
    url: jdbc:mysql://192.168.176.1/senta?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
  application:
    name: server1
  cloud:
    nacos:
      discovery:
        server-addr : 127.0.0.1:8848

seata:
  enabled: true
  application-id: ${spring.application.name}
  enable-auto-data-source-proxy: true
  tx-service-group: SEATA_GROUP
  service:
    vgroupMapping:
      SEATA_GROUP: default    需要在nacos配置中心中增加对应的事务分组配置项,或者将此处事务分组名使用nacos.config 中 配置的默认配置项
      
  config:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      group : "SEATA_GROUP"
      namespace: ""
      username: "nacos"
      password: "nacos"
  registry:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      namespace: ""
      group: SEATA_GROUP
      cluster: default
      application: seata-server

注意点:

class: io.seata.discovery.registry.RegistryService

default String getServiceGroup(String key) {
        key = PREFIX_SERVICE_ROOT + CONFIG_SPLIT_CHAR + PREFIX_SERVICE_MAPPING + key;
        if (!SERVICE_GROUP_NAME.contains(key)) {
            ConfigurationCache.addConfigListener(key);
            SERVICE_GROUP_NAME.add(key);
        }
        return ConfigurationFactory.getInstance().getConfig(key);
    }

PREFIX_SERVICE_ROOT: service
CONFIG_SPLIT_CHAR: .
PREFIX_SERVICE_MAPPING: vgroupMapping.
通过此处就可以生成一个key 而后将会根据此
key*在nacos中寻找服务
*

详情见:http://seata.io/zh-cn/docs/user/txgroup/transaction-group.html

搭建的其他部分见引用:
https://blog.csdn.net/weixin_45481406/article/details/114763504

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值