In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the message-driven micro-service framework". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "what is a message-driven micro-service framework"!
Introduction to Spring Cloud Stream
The official definition of Spring Cloud Stream is a framework for building message-driven capabilities for microservice applications. It provides personalized automatic configuration for the message middleware products of some suppliers, and introduces three core concepts: publish-subscribe, consumption group and partition.
Spirng Cloud Stream essentially integrates Spring Boot and Spring Integration to implement a lightweight message-driven micro-service framework.
Through the use of Spring Cloud Stream, developers can effectively simplify the complexity of using message middleware, so that system developers can have more energy to focus on the core business logic processing.
Spring Cloud Stream is implemented based on Spring Boot, so it inherits the advantages of Spring Boot, and the automatic configuration feature can help us get started quickly.
However, Spring Cloud Stream currently only supports automatic configuration of two message middleware, RabbitMQ and Kafka.
Interpretation of relevant knowledge points
"1. What is an event-driven architecture? "
As shown in the figure above, sometimes a service in the system publishes an event due to a user action or internal behavior, and the service knows that the event will be consumed by other services at some point in the future. but we don't know who the service is, and we don't care when it is consumed. Similarly, the service that consumes the event does not necessarily need to know which service the event was published by.
The dotted line between the event producer and the consumer represents a loose relationship with no direct invocation. Systems that meet the above characteristics represent a loosely coupled architecture, often referred to as event-driven architecture, where events can also be understood as a message sent between services. Event-driven architecture is essentially an architectural design style, and there are many ways and tools to implement it. In the Spring Cloud family, this tool is Spring Cloud Stream.
In fact, Spring Cloud Stream implements the mechanism of message publishing and consumption based on Spring Integration and provides a layer of encapsulation. Many concepts and implementation methods about message publishing and consumption are essentially dependent on Spring Integration. Behind Spring Integration, it relies on Spring Messaging components to implement the infrastructure of the message processing mechanism.
"2. What is Spring Messaging? "
Spring Messaging is a module in Spring Framework, and its function is the programming model of unified messaging.
The model corresponding to each message Messaging includes a message body Payload and a message header Header.
Package org.springframework.messaging; public interface Message {T getPayload (); MessageHeaders getHeaders ();}
The message channel MessageChannel is used to receive messages, and the send method is called to send messages to this message channel.
@ FunctionalInterface public interface MessageChannel {long INDEFINITE_TIMEOUT =-1; default boolean send (Message message) {return send (message, INDEFINITE_TIMEOUT);} boolean send (Message message, long timeout);}
"how can messages in the message channel be consumed?"
The SubscribableChannel implementation of the message channel that can be subscribed by the subinterface of the message channel, subscribed by the MessageHandler message handler:
Public interface SubscribableChannel extends MessageChannel {boolean subscribe (MessageHandler handler); boolean unsubscribe (MessageHandler handler);}
Messages are actually consumed / processed by MessageHandler:
@ FunctionalInterface public interface MessageHandler {void handleMessage (Message message) throws MessagingException;}
Some other functions are derived from the message model within Spring Messaging, such as:
Message receiving parameters and return value processing: message receiving parameter processor HandlerMethodArgumentResolver is used with @ Header, @ Payload and other annotations; HandlerMethodReturnValueHandler after message reception is used with @ SendTo annotation
Message body content converter MessageConverter
Unified Abstract message delivery template AbstractMessageSendingTemplate
Message channel interceptor ChannelInterceptor
"3. What is Spring Integration? "
Spring cloud stream is a framework built on top of Spring Boot and Spring Integration, making it easy for developers to quickly build Message-Driven-based systems.
Brief introduction of Spring Integration & Enterprise Integration Patterns
Enterprise Integration Patterns is a way of data exchange among systems used in enterprise application development practice summarized by Gregor Hohpe and Bobby Woolf in Enterprise Integration Patterns.
Spring Integration is the implementation and adaptation of Spring framework to Enterprise Integration Patterns.
Spring Integration implements lightweight messaging in Spring-based applications and supports integration with external systems by declaring adapters. These adapters provide a higher level of abstraction than Spring's support for remoting, messaging, and scheduling.
The main goal of Spring Integration is to provide a simple model to build enterprise integration solutions while maintaining separation of concerns, which is critical to generating maintainable and testable code.
There are several common modes of enterprise integration data transfer:
File transfer: system A uses FTP polling to obtain the files generated by system B.
Shared database: system An and system B share a database table and entity classes.
RPC calls: systems An and B expose services that can be invoked between each other, such as SOAP, REST.
Messaging: system An and system B exchange data through the intermediate price of the message.
Spring Cloud Stream action
Unaware use of message middleware
Spring Cloud Stream solves the problem of developers' unaware use of message middleware, because the further encapsulation of message middleware by Spring Cloud Stream can make it unaware of middleware at the code level.
High decoupling of middleware and services
Spring Cloud Stream carries out configuration isolation, only needs to adjust the configuration, and can dynamically switch middleware (such as rabbitmq to kafka) in development, so that micro-service development is highly decoupled and services can pay more attention to their own business processes.
Core concept and Application Model of Spring Cloud Stream
"main concepts"
Spring Cloud Stream provides personalized automated configuration for major messaging middleware products, citing three core concepts of publish-subscribe, consumer group and partition.
Spring Cloud Stream provides many abstract and basic components to simplify message-driven micro-service applications. Contains the following:
Application Model of Spring Cloud Stream
Bind abstraction
Persistent publish / subscribe support
Consumer group support
Sharding support (Partitioning Support)
Pluggable API
"application model"
Spring Cloud Stream consists of a neutral middleware kernel.
Spring Cloud Stream injects input and output channels, the application communicates with the outside world through these channels, and channels connects to the external brokers through an explicit middleware Binder.
"Channel"
Channel describes the channel through which messages flow from the application to the Binder, that is, input and output in Application Model.
"Binder"
Binder is a very important concept in Spring Cloud Stream. It is the middle layer between application and message middleware, which perfectly shields the implementation differences of different message middleware and can be simply compared to Adapter.
Spring Cloud Stream officially provides Binder implementations of two mainstream messaging middleware, spring-cloud-stream-binder-kafka and spring-cloud-stream-binder-rabbit. It also provides a special TestSupportBinder for testing, which developers can use directly to test the received content of the channel.
Of course, Spring Cloud Stream also allows developers to implement Binder for other MQ through its SPI. At present, a number of MQ products provide third-party Binder implementation, refer to the official document Binder Implementions. If you want to implement your own Binder, please refer to the official document Binder SPI.
"Bindings"
Binding is a bridge model used to describe the MQ middleware to the application, that is, the description of the binding relationship between Binder plus inputs and outputs each channel
"binding abstraction of major message middleware"
Spring Cloud Stream provides Binder implementations of Kafka,Rabbit MQ,Redis, and Gemfire. Spring Cloud Stream also includes an TestSupportBinder,TestSupportBinder reserving an unchanged channel to facilitate direct and reliable communication with the channels.
"Integrated Kafka"
Org.springframework.cloud spring-cloud-stream-binder-kafka
"Integrated RabbitMQ"
Org.springframework.cloud spring-cloud-starter-stream-rabbit
Partition support
Spring Cloud Stream supports data partitioning between multiple instances of an application, in which case physical communication media (for example, topic agents) are treated as multi-partition structures. One or more producer application instances send data to multiple consumer application instances and ensure that data with common characteristics are processed by the same consumer instance.
Spring Cloud Stream provides a general abstraction for partitioning in a uniform manner, so partitions can be used for agents with their own partitions (such as kafka) or unpartitioned agents (such as rabbiemq)
Partitioning is a very important concept in stateful processing, and its importance lies in performance and consistency, to ensure that all relevant data are processed at the same time, for example, in the case of time window averaging, the measurements of a given sensor should be calculated by the same application instance.
Thank you for your reading. the above is the content of "what is the message-driven micro-service framework". After the study of this article, I believe you have a deeper understanding of what is a message-driven micro-service framework. Specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.