Skip to content

消息总线的使用 ​

一、依赖 ​

在客户端添加依赖,不是在config-server添加

xml
<!--配置中心结合消息队列 springboot监控-->
<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>

二、配置信息 ​

yaml
spring:
  #rabbitMQ配置
  rabbitmq:
    host: 192.168.43.190
    port: 5672
    username: guest
    password: guest
#消息总线-暴露全部的监控信息
management:
  endpoints:
    web:
      exposure:
        include: "*"

三、动态刷新配置-通过请求 ​

通过请求手动触发刷新配置。新建一个请求类,增加注解@RefreshScope,只要请求这个类的任何路径,服务器就会动态刷新配置。生产环境建议不启用

java
@RefreshScope
@RestController
@RequestMapping("/refresh")
public class RefreshConfig {
    @PostMapping("/config")
    public String reflesh() {
        return "";
    }
}