SpringCloud Bus消息总线入门

SpringCloud Bus简介

引用 Spring Cloud Bus 官方文档说明:
Spring Cloud Bus links the nodes of a distributed system with a lightweight message broker. This broker can then be used to broadcast state changes (such as configuration changes) or other management instructions. A key idea is that the bus is like a distributed actuator for a Spring Boot application that is scaled out. However, it can also be used as a communication channel between apps.

Spring Cloud Bus使用轻量级消息代理连接分布式系统的各个节点,这样做可以用于系统状态变更广播(例如,配置变更)或其他管理指令。总线就像是一个Spring Boot应用程序扩展出来的分布式执行器,也可以用作应用程序之间的通信通道。

换句话说,当多个微服务的配置信息发生变更的时候,不需要我们多次调用每个服务的端点接口 actuator/refresh 来让服务获取最新的配置信息。现在只需要调用一次就可以通过消息总线广播到其他微服务来主动获取最新的配置。为了更方便的理解消息总线的作用,整体架构图如下:

如何使用SpringCloud Bus

1、项目搭建说明

2、搭建过程

以 provider-demo 搭建为例,总体包结构如下图所示:在这里插入图片描述

  • pom文件添加 spring-cloud-starter-bus-kafka 消息总线依赖
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.RELEASE</version>
    <relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>provider-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>provider-demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version></
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值