首页 > 其他 > 详细

SrpingCloud 之SrpingCloud config分布式配置中心实时刷新

时间:2018-11-15 23:36:50      阅读:243      评论:0      收藏:0      [点我收藏+]

默认情况下是不能及时获取变更的配置文件信息

Spring Cloud分布式配置中心可以采用手动或者自动刷新

 1、手动需要人工调用接口   监控中心

 2、消息总线实时通知  springbus

 

动态刷新数据

在SpringCloud中有手动刷新配置文件和实时刷新配置文件两种方式。

手动方式采用actuator端点刷新数据

实时刷新采用SpringCloud Bus消息总线

 

 

  

actuator端点刷新数据

在config clientr引入 

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

  

yml中开启监控断点

management:
  endpoints:
    web:
      exposure:
        include: "*"

 同时在controller加 @RefreshScope 

package com.toov5.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class TestController {
    @Value("${motto}")   //配置的key
  private String motto;
    
    @RequestMapping("/getMotto")
    public String getMotto() {
        return motto;
    }
}

 

开启: 修改git上的配置文件信息

必须要用post请求!

技术分享图片

http://127.0.0.1:8882/actuator/refresh

 技术分享图片

成功!

 每个客户端都有监听,效果不是很好这样的方式。手动刷新比较好一些。改完了自己手动刷新下 post 调用一下

 

SrpingCloud 之SrpingCloud config分布式配置中心实时刷新

原文:https://www.cnblogs.com/toov5/p/9966822.html

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