springcloud 笔记8 bus 消息总线

消息总线

springcloud bus 消息总线一般配合 springcloud config 一起使用
大纲:
大纲
通知client
通知主config

设计思想

图一:
图一
图二:
在这里插入图片描述

图一. 利用消息总线触发一个客户端/bus/refresh,而刷新所有客户端的配置

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

图二的架构显然更加合适,图一不适合的原因如下

  • 打破了微服务的职责单一性,因为微服务本身是业务模块,它不应该承担配置刷新的职责
  • 打破了微服务各个节点的对等性
  • 有一定的局限性。例如:微服务在迁移时,它的网络地址常常会发生变化,此时如果想要做到自动刷新,那就回增加更多的的修改

给配置中心3344添加消息总线支持

pom.xml

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

application.yaml

spring:
## rabbitmq 相关配置
  rabbitmq:
    host: 192.168.226.128
    port: 5672
    username: guest
    password: guest
## rabbitmq 相关配置, 暴露bus刷新配置的端点
management:
  endpoints:    ## 暴露bus刷新配置的端点
    web:
      exposure:
        include: "bus-refresh"

给配置客户端3355和3366添加消息总线支持

pom.xml

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

application.yaml

spring:
## rabbitmq 相关配置
  rabbitmq:
    host: 192.168.226.128
    port: 5672
    username: guest
    password: guest
## 暴露监控端点
management:
  endpoints:
    web:
      exposure:
        include: "*"

测试:

  1. 修改Gitee上的配置文件增加版本
  2. 各个配置中心的调用脚本
    配置中心: http://localhost:3344/config-dev.yaml
    配置client: http://localhost:3355/configInfo
    配置client: http://localhost:3366/configInfo
  3. curl -X POST “http://localhost:3344/actuator/bus-refresh
  4. 查看结果,全部更新完毕

在这里插入图片描述
在这里插入图片描述

定点通知某个/些config客户端

公式:http://lcoalhost:配置中心的端口号/actuator/bus-refresh/{destination}
/bus-refresh请求不再发送到具体的服务实例上,而是发给config server 。并通过destination参数类指定需要发送更新配置的服务或者实例

如:
curl -X POST “http://localhost:3344actuator/bus-refresh/config-clent:3355”

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值