使用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端:

最低0.47元/天 解锁文章
526

被折叠的 条评论
为什么被折叠?



