Spring Cloud Bus
概述
-
Spring Cloud Bus 是用轻量的消息中间件将分布式的节点连接起来,可以用于广播配置文件的更改或者服务的监控管理。关键的思想就是,消息总线可以为微服务做监控,也可以实现应用程序之间相通信。
-
• Spring Cloud Bus 可选的消息中间件包括 RabbitMQ 和 Kafka 。
- 可以使用Spring Cloud Bus来实现配置的自动更新。
- 需要注意的是Spring Cloud Bus底层是基于RabbitMQ实现的,默认使用本地的消息队列服务,所以需要提前启动本地RabbitMQ服务
1. rabbitmq回顾
#####2. bus-快速入门
-
分别在 config-server 和 config-client中引入 bus依赖:bus-amqp
<!-- bus --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
-
分别在 config-server 和 config-client中配置 RabbitMQ
spring: #配置rabbitmq信息 rabbitmq: host: localhost port: 5672 username: guest password: guest virtual-host: /
-
在config-server中设置暴露监控断点:bus-refresh
# 暴露bus的刷新端点 management: endpoints: web: exposure: include: 'bus-refresh'
-
启动测试
curl -X POST http://localhost:9527/actuator/bus-refresh
启动eureka-server-config、config-server、config-provider、config-consumer
config-consumer http://localhost:9000/order/goods/2
config-provider http://localhost:8001/goods/findOne/2
config-server http://localhost:9527/master/config-dev.yml
https://gitee.com/kd/ittest-config-test/blob/master/config-dev.yml