zoukankan      html  css  js  c++  java
  • 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 

            可以看到有消息传过来 

             

             在请求应用  

      获取到了最新值

  • 相关阅读:
    过河卒 NOIp 2002 dp
    [POI2014]KUR-Couriers BZOJ3524 主席树
    【模板】可持久化线段树 1(主席树)
    EXPEDI
    取石子游戏 BZOJ1874 博弈
    【模板】文艺平衡树(Splay) 区间翻转 BZOJ 3223
    关于表白
    POJ 1951
    Codeforces 1032F Vasya and Maximum Matching dp
    Codeforces 1016F Road Projects
  • 原文地址:https://www.cnblogs.com/qin1993/p/11578671.html
Copyright © 2011-2022 走看看