使用消息队列来实现每次修改完配置文件后,往队列里写一个消息,由spring cloud bus 提供的功能,从队列中读取消息,然后重新加载一次。
也分为客户端 和 服务端
1、服务端配置,配置中心pom中添加依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
2、客户端配置
<!--消息总线依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
消息读写,写在config微服务中,读的配置需要在git上的配置中添加rabbitmq的配置。
注意点:
如果修改git配置中心,实现的是自定义配置而非系统级配置,那就需要在该微服务的控制层添加注解@RefreshScope 实现自定义配置的消息总线刷新。