SpringCloud Bus

1、概述

1⃣️功能:分布式自动刷新配置功能,Spring Cloud Bus 配合 Spring Cloud Config 使用可以实现配置的动态刷新。

2⃣️Bus支持两种消息代理:RabbitMQ 和 Kafka。

3⃣️设计思想

  • 利用消息总线触发一个客户端/bus/refresh,而刷新所有客户端的配置🌟
  • 利用消息总线触发一个服务端ConfigServer的/bus/refresh端点,而刷新所有客户端的配置

2、RabbitMQ环境配置

RabbitMQ_妖孽学长的博客-CSDN博客

3、Config客户端配置

Springcloud Config_妖孽学长的博客-CSDN博客

4、添加消息总线支持

4.1 配置中心服务端

1⃣️Pom

<!--添加消息总线RabbitMQ支持-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

2⃣️yml

#rabbitmq相关配置
rabbitmq:
  host: localhost
  port: 5672
  username: guest
  password: guest

4.2 客户端

1⃣️Pom,如上

2⃣️yml:与config对齐

#rabbitmq相关配置 15672是Web管理界面的端口;5672是MQ访问的端口
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

5、测试

5.1 广播通知

1⃣️启动服务端和客户端

2⃣️访问http://config-3344.com:3344/config-dev.yml、http://localhost:3355/configInfo、http://localhost:3366/configInfo

3⃣️修改Github上配置文件增加版本号,刷新3344即可生效

4⃣️发送curl -X POST "http://localhost:3344/actuator/bus-refresh" 全部生效

5.2 定点通知

1⃣️通知公式curl -X POST "http://localhost:配置中心的端口号/actuator/bus-refresh/{destination}"。

/bus/refresh请求不再发送到具体的服务实例上,而是发给config server并通过destination参数类指定需要更新配置的服务或实例。

destination:spring: application: name: config-client

2⃣️案例:只通知3355,不通知3366

curl -X POST "http://localhost:3344/actuator/bus-refresh/config-client:3355"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值