Spring source analysis of the Spring-messaging module detailed

Source: Internet
Author: User
Tags stomp

0 overview

The Spring-messaging module provides support for integrated messaging APIs and message protocols.

Its code structure is:

Where base defines the message (MessageHeader and body), the message processing MessageHandler, and the sending message Messagechannel.

1. Base module

Its structure is as follows:

which

The message is made up of two parts,

MessageHandler is a convention for handling messages, and spring messaging provides a rich message handling approach.

Messagechannel is a pipeline that behaves as a pipes-and-filters architecture.

2. Converter Converter Module

Provides support for message transformations. The structure is as follows:

As you can see, there is a message to the string, JSON, and byte arrays to convert each other.

3 Core Module

The core module provides a template method for the message, which is structured as follows:

4. Handling the Handler module

The approximate structure is as follows:

which

Handlermethod encapsulates a bean's method-related information (GetMethod () and Getbean () methods), providing a handy tool for accessing method parameters. Handlermethod can obtain the instance of a bean when it is used in bean factory using Createwithresolvedbean.

Messagecondition is a convention that maps conditions to a message.

Handlermethodargumentresolver is a policy interface that parses a parameter value of a method parameter into a context that specifies a message.

Handlermethodreturnvaluehandler is a policy interface that handles returning values from a method handling that triggers a message.

In addition, some annotations are provided:

@interface Header:annotation which indicates that a method parameter should is bound to a message Header.

@interface Headers:annotation which indicates that a method parameter should is bound to the Headers of a message. The annotated parameter must is 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 spec Ific 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 is passed through a {@link messageconverter} to convert it from serialized form with s Pecific MIME type to an Object matching the target method parameter.

@interface SendTo:Annotation that indicates a method ' s return value should is 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.

The stomp,streaming text orientated message Protocol is a streaming text-oriented messaging protocol, a simple text protocol designed for MOM (message oriented middleware, messaging-oriented middleware). It provides an interoperable connection format that allows the stomp client to interact with any stomp message broker (broker), similar to Openwire (a binary protocol). Because of its simple design, it is easy to develop the client, so it is widely used in many languages and various platforms. One of the most popular stomp message agents is Apache ActiveMQ.
See the Chinese version of the detailed agreement. Another stomp architecture is as follows:

(Spring official picture)

6. Support Module

Provides the implementation of the message, as well as the creation of the Messagebuilder and the messageheaderaccessor of the message headers, as well as various Messagechannel implementations and channel interceptor support.

7. TCP Module

The abstraction and implementation of establishing TCP connection through tcpoperations, processing messages through Tcpconnectionhandler, and sending messages via tcpconnectionf are provided on the one hand. On the other hand, it contains support for reactor-based TCP messages.

8 Summary

Spring Framework 4 includes a new module that spring-messaging uses the core concepts of the spring integration project, such as, Message MessageChannelMessageHandler和别的一些可以作为消息架构的基础组件。这个模块同样也提供了一些映射消息到方法的注解,类似于基于编程模型的spring mvc注解。

Spring source analysis of the Spring-messaging module detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.