1. 配置环境html
版本:Spring Boot版本2.0.3.RELEASE,Spring Cloud版本Finchley.SR1,RabbitMQ 3.7.7git
说明:本文章是在http://www.javashuo.com/article/p-cwttcamw-cs.html的基础上完成,web
2. 实现原理(以下图所示)spring
1. 添加依赖服务器
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
2. 修改配置ide
spring: # Rabbitmq配置 rabbitmq: cache: channel: checkout-timeout: 1s host: 192.168.2.246 port: 5672 username: admin password: admin #暴露/actuator/bus-refresh接口 management: endpoints: web: exposure: include: "*"
3. 启动Config-Server,查看MQ,会多出来一个队列post
1. 添加依赖测试
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
2. 添加RabbitMQ配置url
spring: # Rabbitmq配置 rabbitmq: cache: channel: checkout-timeout: 1s host: 192.168.2.246 port: 5672 username: admin password: admin
3. 在使用属性的地方,增长@RefreshScope注解,防止刷新后配置不生效----------但测试发现,不添加@RefreshScope注解也能动态刷新配置spa
//@RefreshScope @Configuration @ConfigurationProperties("aliyun") public class OSSProperties { /** * 内网链接地址 */ private String endpoint; /** * 外网链接地址 */ private String outsideEndpoint; private String accessKeyId; private String accessKeySecret; private String bucketName; /** * 外网访问地址 */ private String url; private String roleArnPro; ...get set... }
1. 启动Client端服务,使用postman请求测试接口
2. 修改git服务器上的配置
3. 调用Config Server的/actuator/bus-refresh接口
Config Server控制台日志:
Config Client控制台日志:
RabbitMQ管理页面:
4. 从新请求测试接口,发如今没重启的状况下,配置已经改变