当前位置:网站首页>Microservice architecture | message bus and driver - [bus & stream]
Microservice architecture | message bus and driver - [bus & stream]
2022-07-20 05:31:00 【Ask the fairy where Penglai is】
INDEX
§1 The message bus
§1.1 brief introduction
The message bus
- In microservice system , Specify a global TOPIC
- this TOPIC Monitored and consumed by all instances of all services
- Be thrown into this TOPIC All the news in , Will be received by all services , So it's called The message bus
BUS
Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or other management instructions. AMQP and Kafka broker implementations are included with the project. Alternatively, any Spring Cloud Stream binder found on the classpath will work out of the box as a transport.
Spring Cloud Bus adopt Lightweight message brokers connect nodes in distributed systems . This can be used for Broadcast status changes ( such as , Configuration update ) Or others Management instructions . This project Include AMQP(Advanced Message Queuing Protocol) The protocol and kafka agent Realization . meanwhile , In the classpath (classpath) Anything you can find on Spring Cloud Stream binder Can be used as a transmission tool out of the box .
§1.2 Use
Get ready rabbitmq
Specific reference middleware | Message queue - [RabbitMq]
all Add the following content to the service that requires message queuing
rely on
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
To configure
spring:
rabbitmq:
host: 192.168.3.7
port: 5672
username: guest
password: guest
§2 Message driven
§2.1 brief introduction
Message driven
Be similar to JDBC , In complex architecture , Different subsystems are likely to use different message oriented middleware , At this time, message driven is often introduced , What works is
- Shield the underlying differences between different message oriented middleware
- Unified messaging programming model
- Reduce the switching cost of different message middleware and the learning cost of R & D personnel
Stream
Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.
The framework provides a flexible programming model built on already established and familiar Spring idioms and best practices, including support for persistent pub/sub semantics, consumer groups, and stateful partitions.
Spring Cloud Stream Is a Highly scalable microservices And Shared message system The connected framework .
This framework provides a flexible programming model , This model is based on the well-known spring Grammar and best practices , Including the release - Subscription persistence 、 Consumer groups and stateful partition Support for
binder
binder It is to access different message oriented middleware Stream The implementation of the , similar jdbc Connection pool and Driver The relationship between .
What we have now binder Realization :
- RabbitMQ
- Apache Kafka
- Kafka Streams
- Amazon Kinesis
- Google PubSub (partner maintained)
- Solace PubSub+ (partner maintained)
- Azure Event Hubs (partner maintained)
- Azure Service Bus (partner maintained)
- AWS SQS (partner maintained)
- AWS SNS (partner maintained)
- Apache RocketMQ (partner maintained)
§2.2 principle
Statement
This post is essentially a note , The following principles do not involve specific code implementation , It's a set of things that the author rolls out to make himself understand
therefore , There is no guarantee that the understanding must be right ( Or there is almost certainly something wrong )
Several important concepts
binder
- Binder , Used to create binding (binding) Tools for
- A binder , Basically, it can be understood as corresponding to a message oriented middleware , It can be analogized as right Database instance The connection of
binding
- binding , Binder (binder) Products
- The two ends of the binding are channel (MessageChannel) and Message exchange (Exchange)
- It can be analogized as right A specific database in the database instance The connection of , But because of binding one end channel (MessageChannel) It has its own direction , So it is only equivalent to the read or write part of a connection
MessageChannel
- channel , The channel of the message , Connecting business services and middleware , For a clear middleware , It acts as an agent (agent, No broker) The role of
- In business , Sending and receiving messages and other operations are actually realized through the operation channel ,Stream It realizes the decoupling of specific middleware through the channel
Source and @Output
- source coordination @EnableBinding Use
- source Marked the current service as a Message source To establish the binding (binding), The message source is the sender of the message 、 Exporter (@Output)
- source A channel is declared in , And mark it as @Output, Here's the picture
Sink and @Input - sink coordination @EnableBinding Use
- sink Marked the current service as a Message receiver To establish the binding (binding), The message receiver is the receiver of the message 、 Input by (@Input)
- sink A channel is declared in , And mark it as @Input
Schematic diagram ( With rabbit For example )
C Bit channel
- Stream Shielding the underlying differences of different message middleware is because it provides a set of general programming model
- The carrier of the general programming model is Message channel (MessageChannel)
The role of the channel
- The channel can be regarded as a set of standards or default implementation , Or simply understood as a standard API
- After the message channel appears , Researchers operate it , Realize the operation of message oriented middleware
How channels work
- In order to achieve the above purpose , The message channel should establish physical connection and logical binding with business services and message middleware at the same time
- Connect to business services , Finally, you can use MessageChannel Of API Realize the proxy of message oriented middleware
- Connect with message oriented middleware , Realize the physical input of messages / Output message middleware
- On the whole : service –( Configure by annotation )– Message channel –( Access through binding connection )– Message middleware
- Through annotation , Mark an input (@Input) Or output (@Output) Direction channel
- Messages sent or monitored by the service , Will be transmitted to the channel first , The latter logic is represented by the channel
- The channel will be configured according to the relevant , Create and specify message middleware instances that specify Exchange Binding relationship of
- The channel realizes the message transmission with the message middleware through binding
§2.3 Use
rely on
According to the actual use of message oriented middleware xxx The content of
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-xxx</artifactId>
</dependency>
To configure
spring:
application:
name: rabbit-stream-provider
rabbitmq:
host: 192.168.3.10
port: 5672
username: guest
password: guest
cloud:
stream:
binders: # Configure the... To be bound here rabbitmq Service information ;
defaultRabbit: # Represents the name of the definition , Used on binding Integrate
type: rabbit # Message component type
bindings: # Integration of services
output: # This name is the name of a channel
destination: studyExchange # Indicates what to use Exchange Name definition
content-type: application/json # Set message type , This time is json, Text is set to “text/plain”
binder: defaultRabbit # Set the specific settings of the message service to be bound
§3 Message queuing common pitfalls
边栏推荐
- 折线图展示数据趋势的同时还能数据筛选
- 分享|2022数字安全产业大数据白皮书(附PDF)
- Ghost keyboard and mouse common method call
- 矩阵与高斯消元【矩阵乘法,高斯消元求线性方程组,求行列式】 全网最详,附例题与姊妹篇 一万三千字详解
- Pinecone trip x starrocks: the practical road of the new paradigm of real-time data warehouse
- 硬核Fiddler抓包工具大型攻略(一)Fiddler基础篇
- Iptables的基本原理
- College sales turned to software testing, from 4K in the third line to 20k in the first line. I pushed another door open
- FPS游戏逆向-方框透视(矩阵)
- cdh配置外部mysql([main] DbCommandExecutor ERROR Error when connecting to database.)
猜你喜欢
CVPR 2022 | Shangtang won the first place in Clic image coding competition
低代码搭建企业财税服务系统案例分析
Apache Hudi data skip technology accelerates queries up to 50 times
wdsr 论文阅读笔记
WSL2 通过 USBIP 连接USB串口设备 JetsonUSB备份刷机
涛思数据时序数据库 TDengine 正式入驻青云云市场
递归实现排列型枚举
Matlab论文插图绘制模板第39期—阶梯图(Stairs)
Wdsr paper reading notes
一文带你浏览Graph Transformers
随机推荐
在 TKE 上安装 harbor
硬核Fiddler抓包工具大型攻略(一)Fiddler基础篇
大专销售转行软件测试,从三线的4K走到一线20K+,我推开了另一扇门
计算str表达式結果
单机高并发模型设计
LeetCode.6115 统计理想数组的数目
北方重工:通过郑州日产产品过程审核
方文档。最API。基于这套Aage,昇腾
Record the relevant use of pyinstaller (py generates executable file)
TOGAF中的本手和妙手
稳定性与高可用保障的工作思路
uniApp填坑之旅
可落地的DDD(7)-战术设计上的一些误区
递归实现排列型枚举
11. Container with the most water
`OI题解` `LeetCode` 2040. 两个有序数组的第 K 小乘积
广发证券在线开户安全吗,需要身份证
Outils de capture de paquets Fiddler hardcore
The original hand and excellent hand in togaf
微服务架构 | 消息总线和驱动 - [Bus & Stream]