7.Bus消息总线
2019-05-28 本文已影响0人
面具猴
0.服务器上安装RabbitMQ组件
一.服务端
1.依赖
<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.配置
#rabbitmq
spring.rabbitmq.host=127.0.0.1
#bus
management.endpoints.web.exposure.include=bus-refresh
二.客户端
1.依赖
<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>
2.配置
在application.properties配置文件中添加
#rabbitmq
spring.rabbitmq.host=127.0.0.1
三.测试
发送post
http://127.0.0.1:8002/actuator/bus-refresh
注意:
以上方式对于框架级别的配置能自由更新,但对于自定义配置@Value("${remoteconfig}")无法起作用
如果想要起作用要在Controller上加注解@RefreshScope