54 消息总线bus

作者: 木子教程 | 来源:发表于2022-01-19 22:15 被阅读0次

在微服务架构中,通常会使用轻量级的消息代理来构建一个共用的消息主题来连接各个微服务实例,它 广播的消息会被所有在注册中心的微服务实例监听和消费,也称消息总线。 SpringCloud中也有对应的解决方案,SpringCloud Bus 将分布式的节点用轻量的消息代理连接起来, 可以很容易搭建消息总线,配合SpringCloud config 实现微服务应用配置信息的动态更新。


image-20220102211404297.png

根据此图我们可以看出利用Spring Cloud Bus做配置更新的步骤:

  • 提交代码触发post请求给bus/refresh
  • server端接收到请求并发送给Spring Cloud Bus
  • Spring Cloud bus接到消息并通知给其它客户端
  • 其它客户端接收到通知,请求Server端获取最新配置
  • 全部客户端均获取到最新的配置

消息总线整合配置中心

(1) 引入依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-bus</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>

(2)服务端配置

server:
 port: 10000 #服务端口
spring:
 application:
   name: config-server #指定服务名
 cloud:
   config:
     server:
       git:
         uri: https://gitee.com/it-lemon/config-repo.git
 rabbitmq:
   host: 127.0.0.1
   port: 5672
   username: guest
   password: guest
management:
 endpoints:
   web:
     exposure:
       include: bus-refresh
eureka:
 client:
   serviceUrl:
     defaultZone: http://127.0.0.1:8761/eureka/
 instance:
   preferIpAddress: true
   instance-id: ${spring.cloud.client.ip-address}:${server.port}
#spring.cloud.client.ip-address:获取ip地址

(3)微服务客户端配置

server:
 port: 9002
eureka:
 client:
   serviceUrl:
     defaultZone: http://127.0.0.1:8761/eureka/
spring:
 cloud:
   config:
     name: product
     profile: dev
     label: master
     discovery:
       enabled: true
       service-id: config-server

需要在码云对应的配置文件中添加rabbitmq的配置信息

image-20220102211635504.png

重新启动对应的eureka-server , config-server , product-service。配置信息刷新后,只需要向配置 中心发送对应的请求,即可刷新每个客户端的配置

相关文章

  • 54 消息总线bus

    在微服务架构中,通常会使用轻量级的消息代理来构建一个共用的消息主题来连接各个微服务实例,它 广播的消息会被所有在注...

  • Bus消息总线

    Bus消息总线 原文在github,有些相对路径连接不能跳转,如想看原文项目地址 spingboot2.1.3加s...

  • Bus 消息总线

    Bus概述 Spring Cloud Bus 是用轻量的消息中间件将分布式的节点连接起来,可以用于广播配置文件的更...

  • Spring Cloud Bus:消息总线

    Spring Cloud Bus:消息总线 Spring Cloud Bus 使用轻量级的消息代理来连接微服务架构...

  • 高级框架第十三天Config:分布式配置中心

    第一部分 Bus:消息总线 主要内容 1.消息总线简介 2.基于消息总线实现全局热刷新 一.消息总线简介 1.什么...

  • Chapter Nine《SpringCloud微服务实战》

    消息总线: Spring Cloud Bus 1.什么是BUS? spring cloud是按照spring的配置...

  • 消息总线-Springcloud Bus

    什么是消息总线 在微服务架构的系统中, 我们通常会使用轻量级的消息代理来构建一个共用的消息主题让系统中所有微服务实...

  • SpringCloud Bus 消息总线

    上一篇文章我们介绍了配置中心,但是现在更新配置还是要重启啊!?所以我们本章就来介绍一个不重启的方法。 相关资料以及...

  • spring cloud bus

    Bus是一个消息总线,config-server和其他服务都通过Bus监听一个消息队列(本例用Kafka), 通过...

  • Spring Cloud 10 -- 通过 Bus 刷新从配置中

    一、对 client01 添加 Bus 相关依赖 二、修改配置文件,添加配置 提示:使用消息总线 Bus ,需要 ...

网友评论

    本文标题:54 消息总线bus

    本文链接:https://www.haomeiwen.com/subject/cosdhrtx.html