SpringCloud Bus动态刷新全局广播

文章目录

代码地址

地址:https://github.com/13thm/study_springcloud/tree/main/days11_ Bus

配置项目

必须先具备良好的RabbitMQ环境先

演示广播效果,增加复杂度,再以3355为模板再制作一个3366

  1. 新建:cloud-config-client-3366
  2. 写pom
  3. 写yml
  4. 主启动类
  5. 写服务类

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

配置修改

  1. 给cloud-config-center-3344配置中心服务端添加消息总线支持
    修改pom 和yml
  2. 给cloud-config-client-3355配置中心服务端添加消息总线支持
    修改pom 和yml
  3. 给cloud-config-client-3366配置中心服务端添加消息总线支持
    修改pom 和yml

测试

先启动!

csharp 复制代码
http://config-3344.com:3344/master/config-dev.yml
csharp 复制代码
http://localhost:3355/configInfo
csharp 复制代码
http://localhost:3366/configInfo

然后再Gitee里面修改

发送一次:curl -X POST "http://localhost:3344/actuator/bus-refresh"

结果:三个都修改了! 成功!


SpringCloud Bus动态刷新定点通知

不想全部通知,只想定点通知

只通知3355 不通知3366

csharp 复制代码
公式:http://localhost:配置中心的端口号/actuator/bus-refresh/

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

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

csharp 复制代码
curl -X POST "http://localhost:3344/actuator/bus-refresh/config-client:3355"

实现了只通知3355 不通知3366

相关推荐
GreenTea4 小时前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调
前端·后端·算法
风流 少年4 小时前
Spring AI 2.0:Memory
java·后端·spring
万少5 小时前
给 DeepSeek Harness 装个"应用商店":一条命令,595 个插件随你逛
前端·javascript·后端
Java成神之路-7 小时前
Spring Cloud 微服务契约先行:为什么 Controller 建议要实现 Feign 接口?
spring·spring cloud·微服务
IT_陈寒9 小时前
Python的GIL让我多写了500行代码
前端·人工智能·后端
Flittly10 小时前
【雕虫大技】Agent 动态 Skill 供应链安全加固(三):输出校验与治理闭环实战
java·spring boot·spring
IT爱学堂10 小时前
精讲软件设计师(软考中级)一站式通关课_实战课程_慕课网
后端
战天战地站房顶10 小时前
在 Windows Docker 中部署 PostgreSQL 17 + pgvector 完整指南
后端
卷无止境11 小时前
FastAPI Guard 全解析,从概念到工程落地的实战指南
后端·python
卷无止境11 小时前
FastAPI Users 全面解析:概念、原理与工程实战
后端·python