SpringCloud配置中心Config+Bus

Maven依赖 

<!--config配置中心服务端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

configServer yaml配置(获取配置git地址、config Bus rabbitMq配置、开启调用endpoint暴露)

spring:
  application:
    name: cloud-configserver
  cloud:
    config:
      server:
        git:
          uri: https://github.com/XXX/cloud-config-repo.git #配置git服务地址
          username:  #配置git用户名
          password:  #配置git密码
          search-paths:
            - cloud-config-repo
      # 读取分支
      label: master
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest
#针对的被调用方微服务名称,不加就是全局生效
#lagou-service-resume:
#  ribbon:
#    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule #负载策略调整
# springboot中暴露健康检查等断点接口
management:
  endpoints:
    web:
      exposure:
        include: "*"
  # 暴露健康接口的细节
  endpoint:
    health:
      show-details: always

ConfigServer Main函数注解配置

 Client端 yaml配置

  cloud:
    # config客户端配置,和ConfigServer通信,并告知ConfigServer希望获取的配置信息在哪个文件中
    config:
      name: clouder-service-resume  #配置文件名称
      profile: dev  #后缀名称
      label: master #分支名称
      uri: http://localhost:9006    #ConfigServer配置中心地址
  rabbitmq:。
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest

Config Bus: 配置中心数据变更,通过刷新Bus请求,将变更配置整体存入到RabbitMq中,对订阅了配置中心的客户端进行广播变更配置

POST请求 http://localhost:9003/actuator/bus-refresh


 

猜你喜欢

转载自blog.csdn.net/qq_42773863/article/details/122462005