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

相关推荐
励志成为糕手9 分钟前
基于SpringBoot的企业考勤管理系统设计与实现
java·spring boot·后端·web·企业应用
e***749521 分钟前
SpringBoot项目集成ONLYOFFICE
java·spring boot·后端
Java天梯之路29 分钟前
Spring Boot 实战:基于 JWT 优化 Spring Security 无状态登录
spring boot·后端
极光代码工作室39 分钟前
基于SpringBoot的校园招聘信息管理系统的设计与实现
java·前端·spring
o***74171 小时前
SpringBoot Maven快速上手
spring boot·后端·maven
krafft1 小时前
从零入门 Spring AI,详细拆解 ChatClient 调用流程和 Advisor 底层原理,小白可入!
java·spring·ai
j***82701 小时前
Spring 中集成Hibernate
java·spring·hibernate
g***96901 小时前
springboot设置多环境配置文件
java·spring boot·后端
h***34631 小时前
spring session、spring security和redis整合的简单使用
redis·spring·bootstrap
q***54752 小时前
springboot之集成Elasticsearch
spring boot·后端·elasticsearch