• 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 

            可以看到有消息传过来 

             

             在请求应用  

      获取到了最新值

  • 相关阅读:
    Server 对象
    Response 对象
    bzoj 5252: [2018多省省队联测]林克卡特树
    bzoj 2167: 公交车站
    bzoj 5315: [Jsoi2018]防御网络
    bzoj 5319: [Jsoi2018]军训列队
    bzoj 4161: Shlw loves matrixI
    bzoj 4942: [Noi2017]整数
    bzoj 2648: SJY摆棋子
    kd-tree 小结
  • 原文地址:https://www.cnblogs.com/qin1993/p/11578671.html
Copyright © 2020-2023  润新知