改造config-client,添加spring-cloud-starter-bus-amqp(消息总线)和spring-boot-starter-actuator(健康监控)的起步依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
消息总线
启动rabbitmq(需安装rabbitmq)
改造config-client,添加spring-cloud-starter-bus-amqp(消息总线)和spring-boot-starter-actuator(健康监控)的起步依赖
新增application.properties,加入以下配置
其中加上rabbitmq的配置,包括地址、端口、用户名、密码。加上springcloud bus的两个配置,并通过
management.endpoints.web.exposure.include对bus-refresh端口进行监控跟踪对application启动类增加@EnableEurekaClient,@EnableDiscoveryClient声明为eureka client,并增加@RefreshScope,打开动态刷新配置
依次启动以下服务
访问http://localhost:8551/c , http://localhost:8552/c 可以看到返回结果
修改仓库为hugeterry version 2,访问http://localhost:8551/actuator/bus-refresh 刷新数据
再次访问http://localhost:8551/c , http://localhost:8552/c 可以看到返回结果
/actuator/bus-refresh接口可以使用destination刷新指定服务,如 “/actuator/bus-refresh?destination=config-client:**” 即刷新服务名为customers的所有服务