(三)springcloud 消息总线-spring cloud bus

RabbitMQ

1、RabbitMQ环境:略

2、每个服务都添加依赖,或者聚合工程中统一添加


org.springframework.boot
spring-boot-starter-actuator


org.springframework.cloud
spring-cloud-starter-bus-amqp

3、配置

每个服务增加开放监控端点,和RabbitMQ链接参数配置

spring:
config:
...
rabbitmq:
port: 5672
username: jianwei
password: 654321
host: localhost

eureka:
...

management:
endpoints:
web:
exposure:
include: "*"

或者在配置仓库增加公共配置:

全部开放监控端点

management:
endpoints:
web:
exposure:
include: "*"

链接rabbitmq

spring:
rabbitmq:
port: 5672
username: jianwei
password: 654321
host: localhost

4、启动服务

打印日志:

这里在网上看到很多个版本,还是以控制台打印的为准

Mapped "{[/actuator/bus-env/{destination}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v2+json || application/json]}"
Mapped "{[/actuator/bus-env],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v2+json || application/json]}"
Mapped "{[/actuator/bus-refresh],methods=[POST]}"
Mapped "{[/actuator/bus-refresh/{destination}],methods=[POST]}"

5、验证:

启动配置服务端和客户端并访问:http://localhost:4001/config/param

响应结果:config-client-example-value bus version0

修改配置文件:

value: config-client-example-value bus version1

向集中配置服务发送请求

POST /actuator/bus-refresh HTTP/1.1
Content-Length: 0
Host: localhost:8888
Content-Type: application/json

HTTP/1.1 204
Date: Mon, 22 Apr 2019 09:36:11 GMT

再次访问:http://localhost:4001/config/param

响应结果:config-client-example-value bus version1

6、指定配置刷新:

/actuator/bus-refresh

通配符匹配刷新:

/actuator/bus-refresh?destination=serviceName:** // 触发serviceName的所有实例

posted @ 2019-04-22 18:54  zuier~  阅读(409)  评论(0)    收藏  举报