Writing asynchronous messaging applications and eventually-consistent systems provides many advantages, including:
编写异步消息传递应用程序和最终一致的系统具有许多优点,包括:
- Maximization of throughput — especially in cases where immediate consistency is not required 吞吐量最大化—特别是在不需要立即一致性的情况下
- Offloading of workflows to provide an immediate response to a user 卸载工作流以向用户提供立即响应
- Ability to scale various portions of the workflow differently as needed 能够根据需要以不同方式扩展工作流的各个部分
- Support of backpressure around system bottlenecks 支持系统瓶颈周围的背压
Modern platforms and frameworks have made writing asynchronous messaging systems very easy. Recently, I have had some time to explore Spring Cloud Stream, and I have come to find that it has many advantages over other frameworks.
现代平台和框架使编写异步消息传递系统变得非常容易。 最近,我花了一些时间来探索Spring Cloud Stream,并且我发现它比其他框架有很多优势。
“Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.
“ Spring Cloud Stream是一个框架,用于构建与共享消息系统连接的高度可扩展的事件驱动型微服务。
“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.” (reference)
“该框架提供了一个灵活的编程模型,该模型基于已经建立并熟悉的Spring习惯用法和最佳实践,包括对持久性发布/订阅语义,使用者组和有状态分区的支持。” ( 参考 )
Recently, Spring Cloud Stream introduced several new features that have made it an easy option for processing asynchronous messaging streams. There are two in particular that I want to focus on.
最近,Spring Cloud Stream引入了一些新功能,这些功能使其成为处理异步消息流的简便选择。 我要特别关注两个。
- Functional paradigm for message processing through spring-cloud-function 通过spring-cloud-function处理消息的功能范式
- Simplified testing with an improved test binder 使用改进的测试粘合剂简化测试
背景 (Background)
Spring Cloud Stream evolved out of the Spring Integration project as it embraced Spring Boot and moved into the modern cloud era. Spring Cloud Stream relies on the concept of a binder to handle the integration with a messaging or event streaming framework. At the time of publication, there were binders for Apache Kafka, Kafka Streams, Rabbit MQ, Azure Event Hubs, Google Cloud PubSub, and many others (see the list).
Spring Cloud Stream包含Spring Boot,并脱离了Spring Integration项目,并进入了现代云时代。 Spring Cloud Stream依靠绑定器的概念来处理与消息传递或事件流框架的集成。 在发布之时,有用于Apache Kafka,Kafka Streams,Rabbit MQ,Azure Event Hubs,Google Cloud PubSub以及许多其他文件夹的活页夹( 请参阅清单 )。
The binders support the core features of modern messaging/eventing systems:
活页夹支持现代消息传递/事件系统的核心功能:
- Publish/Subscribe (multiple consumers of the same data) 发布/订阅(相同数据的多个使用者)
- Consumer Groups (horizontal scaling of a single consumer) 消费者组(单个消费者的水平扩展)
- Partitioning 分区
- Message-driven consumers 消息驱动的消费者
- Polling-based consumers 基于轮询的消费者
活页夹 (Binder)
A binder handles the integration with a single framework. This abstraction allows your code to be middleware-neutral, focusing only on core business logic. The application core only needs to interact with a canonical message.
活页夹通过单个框架处理集成。 这种抽象允许您的代码与中间件无关,仅关注核心业务逻辑。 应用程序核心仅需要与规范消息进行交互。
Binders can be used on both the input and output side to interact with producers or consumers of