1、config-server服务端
引入依赖
<!--actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
添加配置
spring
rabbitmq:
username: guest
password: guest
host: 127.0.0.1
port: 5672
virtual-host: /
#暴露端口
management:
endpoints:
web:
exposure:
include: bus-refresh
2、config-client客户端
引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
添加配置
spring
rabbitmq:
username: guest
password: guest
host: 127.0.0.1
port: 5672
virtual-host: /
注:springboot的版本不能高于spring-cloud-stater-bus-amqp:如前者为2.0.1后者为2.0.0启动报错
测试:
1、修改githup仓库配置:添加hello2和hello8
2、用Insomnia模拟post请求http://localhost:9011/actuator/bus-refresh
3、config-client客户端控制台输出:Received remote refresh request. Keys refreshed [config.client.version, hello2, hello8]