Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh
上一篇文章讲了SpringCloudConfig 集成Git仓库,配和 Eureka 注册中心一起使用,但是我们会发现,修改了Git仓库的配置后,需要重启服务,才可以得到最新的配置,这一篇我们尝试使用 Refresh 实现主动获取 Config Server 配置服务中心的最新配置
把上一篇,示例代码下载,才可以进行一下的操作,下载地址在文章末尾
spring-cloud-eureka-servicespring-cloud-config-serverspring-cloud-eureka-provider-1spring-cloud-eureka-provider-2spring-cloud-eureka-provider-3spring-cloud-feign-consumer
Config Client
修改第九篇文章项目
spring-cloud-eureka-provider-1spring-cloud-eureka-provider-2spring-cloud-eureka-provider-3
添加依赖
<!-- actuator 监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
安全认证
在 application.properties 添加以下配置.关闭安全认证
#关闭刷新安全认证
management.security.enabled=false
值是false的话,除开health接口还依赖endpoints.health.sensitive的配置外,其他接口都不需要输入用户名和密码了
开启 refresh
在程序的启动类 EurekaProviderApplication 通过 @RefreshScope 开启 SpringCloudConfig 客户端的 refresh 刷新范围,来获取服务端的最新配置,@RefreshScope要加在声明@Controller声明的类上,否则refresh之后Conroller拿不到最新的值,会默认调用缓存。
package io.ymq.example.eureka.provider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RefreshScope
@RestController
@EnableEurekaClient
@SpringBootApplication
public class EurekaProviderApplication {
@Value("${content}")
String content;
@Value("${server.port}")
String port;
@RequestMapping("/")
public String home() {
return "Hello world ,port:" + port+",content="+content;
}
public static void main(String[] args) {
SpringApplication.run(EurekaProviderApplication.class, args);
}
}
测试服务
按照顺序依次启动项目
spring-cloud-eureka-servicespring-cloud-config-serverspring-cloud-eureka-provider-1spring-cloud-eureka-provider-2spring-cloud-eureka-provider-3spring-cloud-feign-consumer启动该工程后,访问服务注册中心,查看服务是否都已注册成功:http://localhost:8761/
- 在git仓库修改值后在浏览器访问
http://127.0.0.1:9000/hello 刷新配置
- 通过 
Postman发送POST请求到:http://localhost:8081/refresh,http://localhost:8083/refresh, 访问服务,或者在浏览器访问
http://127.0.0.1:9000/helloF5 刷新发现:服务8082 没有刷新到最新配置 因为没有手动触发更新
Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh的更多相关文章
- springCloud学习-高可用的分布式配置中心(Spring Cloud Config)
		
1.简介 高可用的分布式配置中心,即将配置中心做成一个微服务,将其集群化,从而达到高可用.config-server和config-client向eureka-server注册,且将config-se ...
 - Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务
		
上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...
 - Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
		
在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config,它支持配 ...
 - 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)
		
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
 - 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
		
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
 - SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
		
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
 - SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
		
版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...
 - Spring Cloud(十一)高可用的分布式配置中心 Spring Cloud Bus 消息总线集成(RabbitMQ)
		
详见:https://www.w3cschool.cn/spring_cloud/spring_cloud-jl8a2ixp.html 上一篇文章,留了一个悬念,Config Client 实现配置的 ...
 - SpringCloud学习(七)高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
		
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 准备工作 ...
 
随机推荐
- Oracle11g安装与卸载教程
			
1.1,前言: 电脑太卡,鄙人穷屌丝啊,没钱买新电脑,想想周六日还要耍游戏就给电脑重做了个系统,糟糕的是电脑上的各种环境,工具都需要重新装一边,包括oracle数据库- -,依稀记得昨天装了一上午的数 ...
 - C++ fill   fill_n  generate   generate_n
			
#include <iostream>#include <algorithm>#include <vector>#include <list>#incl ...
 - 一百三十五:CMS系统之UEditoe编辑器集成以及配置将图片上传到七牛
			
富文本编辑框,选择UEditor 下载地址:http://ueditor.baidu.com/website/download.html 使用说明:http://fex.baidu.com/uedit ...
 - jQuery.fn.extend与jQuery.extend的区别
			
jquery 本身并不提供 jQuery.color() 这个方法,如果我们需要对jQuery本身提供的方法进行扩展,则我们就需要是用jQuery.fn.extend: jQuery.fn.exten ...
 - awk工具的基本用法
			
awk文本过滤的基本用法 1)基本操作方法 格式:awk [选项] '[条件]{指令}' 文件 其中,print 是最常用的编辑指令:若有多条编辑指令,可用分号分隔. Awk过滤数据时支持仅打印某一列 ...
 - Official Program for CVPR 2015
			
From: http://www.pamitc.org/cvpr15/program.php Official Program for CVPR 2015 Monday, June 8 8:30am ...
 - OpenCV.3.4.6.附加依赖项
			
ZC:VS2015 "项目属性 --> 链接器--> 输入--> 附加依赖项" 中 添加内容 1.E:\OpenCV_something\opencv-3.4.6 ...
 - spring中的BeanDefinitionRegistryPostProcessor
			
spring中的BeanDefinitionRegistryPostProcessor是BeanFactoryPostProcessor的子接口,BeanFactoryPostProcessor的作用 ...
 - 《C专家编程》读书笔记之第1~4章
			
一.C:穿越时空的迷雾 1. C标准中定义了描述编译器的特点的一些术语: (1) 由编译器定义的(imprementation-defined) 由编译器设计者决定如何处理.例如:整型数右移时要不要扩 ...
 - [转帖]Google Chrome 解决 “您的连接不是私密连接”
			
Google Chrome 解决 “您的连接不是私密连接” 和被毒霸劫持 自己搭建了 k8s的 dashboard 结果 chrome 最新版本的打不开了.. 百度了下 园友的解决方案很完美 这里面转 ...