首页 > 编程语言 > 详细

Spring Cloud Bus 自动更新配置

时间:2019-09-24 16:15:55      阅读:82      评论:0      收藏:0      [点我收藏+]

---恢复内容开始---

Spring Cloud Config 结合 Spring Cloud bus 实现 git 仓库提交配置文件 触发消息队列 应用自动更新配置

 

技术分享图片

 

 

1. config 服务端 添加依赖  

    

  <dependency>
       <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
  </dependency>

  在配置中加入 

 

management:
  endpoints:
    web:
      exposure:
        include: bus-refresh

        暴露bus-refresh 接口  * 暴露所有接口

 

2. config 客户端 加入依赖 

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

 

在需要读取配置的地方加入  @RefreshScope 注解   通过 @Value 或 @ConfigurationProperties 读取 配置

技术分享图片

 

技术分享图片

 

 

 

启动项目  

 打开RabbitMQ  确认加入队列成功

技术分享图片

 

 

   以 gitee为例   

   技术分享图片

 

            修改后提交

            访问配置中心  

            技术分享图片

 

        已更改  但是应用中没有更新 ,现在请求 

          http://localhost:8888/actuator/bus-refresh 

        可以看到有消息传过来 

         技术分享图片

 

         在请求应用  

技术分享图片

 

  获取到了最新值

Spring Cloud Bus 自动更新配置

原文:https://www.cnblogs.com/qin1993/p/11578671.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!