Source code analysis of spring-messaging module

0 Overview

The spring-messaging module provides support for integrating messaging api and messaging protocol.
The code structure is: the
Source code analysis of spring-messaging module
base defines the message Message (MessageHeader and body), the message processing MessageHandler, and the sending message MessageChannel.

1. base module

Its structure is as follows:
Source code analysis of spring-messaging module
Among them:
message consists of two parts,
Source code analysis of spring-messaging module
MessageHandler is an agreement to process messages, spring messaging provides a wealth of message processing methods.
MessageChannel represents the pipeline of the pipes-and-filters architecture.
Source code analysis of spring-messaging module

2. Converter module

Provide support for message conversion. Its structure is as follows:
Source code analysis of spring-messaging module
As can be seen from the above figure, there are conversions between messages to string, json, and byte arrays.

3. Core core module

The core module provides a message template method, and its structure is as follows:
Source code analysis of spring-messaging module

4. Processing the handler module

The general structure is as follows:
Source code analysis of spring-messaging module

Among them,
HandlerMethod encapsulates a bean's method related information (getMethod() and getBean() methods), and provides a convenient tool for accessing method parameters. HandlerMethod can use createWithResolvedBean in the bean factory to obtain the instance of the bean.
MessageCondition is a convention that maps conditions to messages.
HandlerMethodArgumentResolver is a strategy interface that resolves method parameters to the parameter value of the specified Message in the Context.
HandlerMethodReturnValueHandler is a strategy interface that handles the return value from the method Handling that triggers a Message.
In addition, some notes are also provided:

@interface Header:Annotation which indicates that a method parameter should be bound to a message header.
@interface Headers:Annotation which indicates that a method parameter should be bound to the headers of a message. The annotated parameter must be   assignable to {@link java.util.Map} with String keys and Object values.
@interface MessageExceptionHandler: Annotation for handling exceptions thrown from message-handling methods within a specific handler class.
@interface MessageMapping:Annotation for mapping a {@link Message} onto message-handling methods by matching to the message destination.
@interface Payload:Annotation that binds a method parameter to the payload of a message. The payload may be passed through a {@link   MessageConverter} to convert it from serialized form with specific MIME type to an Object matching the target method parameter.
@interface SendTo:Annotation that indicates a method's return value should be converted to a {@link Message} and sent to the specified destination.

5.Simp module

Contains general support for simple message protocols such as the STOMP protocol.
STOMP, Streaming Text Orientated Message Protocol, is a stream text oriented message protocol, a simple text protocol designed for MOM (Message Oriented Middleware, message-oriented middleware). It provides an interoperable connection format that allows STOMP clients to interact with any STOMP message broker (Broker), similar to OpenWire (a binary protocol). Because of its simple design and easy development of clients, it is widely used in multiple languages ​​and multiple platforms. The most popular STOMP message broker is Apache ActiveMQ. Please refer to the Chinese version of the detailed agreement. Another stomp architecture is as follows:
Source code analysis of spring-messaging module
(spring official picture)

6. Support module

Provides the implementation of Message, the MessageBuilder that creates the message and the MessageHeaderAccessor that gets the message header, as well as various MessageChannel implementations and channel interceptor support.

7. tcp module

On the one hand, it provides abstraction and implementation of establishing tcp connection through TcpOperations, processing messages through TcpConnectionHandler and sending messages through TcpConnectionf; on the other hand, it includes support for tcp messages based on Reactor.

8 Summary

Spring Framework 4 includes a new spring-messaging module, which uses the core concepts of Spring Integration project such as Message, MessageChannel, MessageHandler and others as the basic components of the message architecture. This module also provides some annotations for mapping messages to methods, similar to the spring mvc annotations based on the programming model.

Guess you like

Origin blog.51cto.com/15015181/2556231