Spring Cloud Bus 自动更新配置

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

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 

        可以看到有消息传过来 

         

         在请求应用  

  获取到了最新值

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