• 消息总线SpringCloudBus


    在不重启微服务的情况
    下更新配置如何来实现呢? 我们使用SpringCloudBus来实现配置的自动更新。
     
    引入依赖 
    <dependency> 
       <groupId>org.springframework.cloud</groupId> 
       <artifactId>spring‐cloud‐bus</artifactId> 
    </dependency> 
    <dependency> 
       <groupId>org.springframework.cloud</groupId> 
       <artifactId>spring‐cloud‐stream‐binder‐rabbit</artifactId> 
    </dependency>

    配置文件 

       rabbitmq: 
           host: 127.0.0.1 
    management: #暴露触发消息总线的地址 
         endpoints:
             web:
                 exposure: 
                     include: bus‐refresh

    客户端  

     引入依赖 

    <dependency>
       <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring‐cloud‐bus</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId>
    <artifactId>spring‐cloud‐stream‐binder‐rabbit</artifactId>
    </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring‐boot‐starter‐actuator</artifactId>
    </dependency>

    配置文件中配置rabbitmq

    rabbitmq:
        host: 127.0.0.1

    测试 

    Url: http://127.0.0.1:8888/actuator/bus-refresh Method: post
     
    自定义配置文件的读取  
    @RefreshScope     //注解@RefreshScope 此注解用于刷新配置
    @RestController
    public class TestController {
    @Value("${sms.ip}") 
    private String ip; 
    @RequestMapping(value = "/ip", method = RequestMethod.GET) 
    public String ip() {
    return ip;
    }
    }
  • 相关阅读:
    iOS
    iOS
    iOS
    iOS
    iOS
    使用jquery获取radio的值
    CSS margin属性与用法教程
    CSS框架960Grid从入门到精通一步登天
    从程序员到项目经理
    华为离职副总裁徐家骏:年薪千万的工作感悟
  • 原文地址:https://www.cnblogs.com/qin1993/p/12573321.html
Copyright © 2020-2023  润新知