微服配置中心Config整合Bus通过rabbitmq方式总线通知动态更新配置

一、Config环境搭建

微服务Config配置中心动态刷新配置参数

二、Bus相关依赖

配置中心

server:
  port: 3344
spring:
  application:
    name: cloud-config-center
  cloud:
    config:
      server:
        git:
          uri: https://github.com/hqzhen/springcloud-config.git
          ## 搜索目录
          search-paths:
            - springclpud-config
      ### 读取分支
      label: master
  ## rabbitmq相关配置,
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

eureka:
  instance:
    hostname: cloud-config-service
  client:
    #表示是否将自己注册进Eureka Server 默认为true
    register-with-eureka: true
    #是否从Eureka Server抓取已有的注册信息,默认为true。单节点无所谓。集群必须设置为true才能配合ribbon使用负载均衡
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
##暴露刷新配置的端点
management:
  endpoints:
    web:
      exposure:
        include: 'bus-refresh'

 客户端

server:
  port: 3355
spring:
  application:
    name: cloud-config-client
  cloud:
    ## Config客户端配置
    config:
      #分支名称
      label: master
       #配置文件名称
      name: config
      #读取文件后缀
      profile: dev
      uri: http://localhost:3344 #远程配置中心地址
  ## rabbitmq相关配置
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
eureka:
  instance:
    hostname: cloud-config-client
  client:
    #表示是否将自己注册进Eureka Server 默认为true
    register-with-eureka: true
    #是否从Eureka Server抓取已有的注册信息,默认为true。单节点无所谓。集群必须设置为true才能配合ribbon使用负载均衡
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
# 自定义属性
config:
  info: test
# 暴露监控端点
management:
  endpoints:
    web:
      exposure:
        include: "*"

server:
  port: 3366
spring:
  application:
    name: cloud-config-client
  cloud:
    ## Config客户端配置
    config:
      #分支名称
      label: master
       #配置文件名称
      name: config
      #读取文件后缀
      profile: dev
      uri: http://localhost:3344 #远程配置中心地址
  ## rabbitmq相关配置,
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

eureka:
  instance:
    hostname: cloud-config-client
  client:
    #表示是否将自己注册进Eureka Server 默认为true
    register-with-eureka: true
    #是否从Eureka Server抓取已有的注册信息,默认为true。单节点无所谓。集群必须设置为true才能配合ribbon使用负载均衡
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
# 自定义属性
config:
  info: test
# 暴露监控端点
management:
  endpoints:
    web:
      exposure:
        include: "*"

 三、启动项目测试

1)、启动微服项目

2)、检查ribbitmq

3)、检查修改前访问客户端

github默认配置

客户端当前读取的配置

4)、修改配置信息测试配置中心通过bus动态广播

修改配置

刷新配置中心广播到所有服务

5)、再次检查客户端是否全部刷新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值