关于spring cloud config自动刷新配置

使用spring cloud config统一配置中心,对于配置文件的修改,可以通过/refresh端点进行手动刷新,但是随着微服务节点的增多,实现自动刷新是有必要的。–摘自某博客语录

使用spring cloud bus实现配置的自动刷新。
spring cloud bus使用轻量级的消息代理,例如RabbitMQ,Kafka,redis连接分布式系统中的其他节点,通过广播的方式,将配置信息的修改传播给其他节点。

查看spring cloud官方文档,可以看到如下描述:

Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the classpath. 
To enable the bus, add spring-cloud-starter-bus-amqp or spring-cloud-starter-bus-kafka to your 
dependency management. Spring Cloud takes care of the rest. Make sure the broker (RabbitMQ or 
Kafka) is available and configured. When running on localhost, you need not do anything. If you run 
remotely, use Spring Cloud Connectors or Spring Boot conventions to define the broker credentials, 
as shown in the following example for Rabbit:

application.yml. 

spring:
  rabbitmq:
    host: mybroker.com
    port: 5672
    username: user
    password: secret
The bus currently supports sending messages to all nodes listening or all nodes for a particular 
service (as defined by Eureka). The /bus/* actuator namespace has some HTTP endpoints. 
Currently, two are implemented. The first, /bus/env, sends key/value pairs to update each node’s 
Spring Environment. The second, /bus/refresh, reloads each application’s configuration, as though 
they had all been pinged on their /refresh endpoint.

server端:
引入依赖:spring-cloud-starter-bus-amqp或spring-cloud-starter-bus-kafka,远程情况下,配置消息代理的相关参数(本地运行无需配置)。
启动类添加@EnableConfigServer,开启支持。
client端:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值