日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring源码分析之spring-messaging模块详解

發布時間:2025/4/5 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring源码分析之spring-messaging模块详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

0 概述

spring-messaging模塊為集成messaging api和消息協議提供支持。

其代碼結構為:

其中base定義了消息Message(MessageHeader和body)、消息處理MessageHandler、發送消息MessageChannel。

1. base模塊

其結構如下所示:

其中:

message由兩部分組成,

MessageHandler是一個處理消息的約定,spring messaging提供了豐富的消息處理方式。

MessageChannel表現為pipes-and-filters架構的管道。

2. 轉換器converter模塊

? ? 對消息轉換提供支持。其結構如下:

從上圖可以看出,有消息到string、json、byte數組之間的相互轉換。

3. 核心core模塊

核心模塊提供消息的模板方法,其結構如下:

4. 處理handler模塊

?

?大致架構如下:

?

其中,

HandlerMethod封裝了一個bean的方法相關信息(getMethod()和getBean()方法),提供了訪問方法參數的便利工具。HandlerMethod可以在bean factory中使用createWithResolvedBean獲取bean實例時獲取該實例。

MessageCondition是一個將conditions映射到message的約定。

HandlerMethodArgumentResolver 是一個解析方法參數到Context中指定Message的參數值的策略接口。

HandlerMethodReturnValueHandler是一個處理從觸發一個Message的method Handling返回值的策略接口。

另外,也提供了部分注解:

@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模塊

包含諸如STOMP協議的簡單消息協議的通用支持。

STOMP,Streaming Text Orientated Message Protocol,是流文本定向消息協議,是一種為MOM(Message Oriented Middleware,面向消息的中間件)設計的簡單文本協議。它提供了一個可互操作的連接格式,允許STOMP客戶端與任意STOMP消息代理(Broker)進行交互,類似于OpenWire(一種二進制協議)。由于其設計簡單,很容易開發客戶端,因此在多種語言和多種平臺上得到廣泛應用。其中最流行的STOMP消息代理是Apache ActiveMQ。
詳細協議內容中文版本參見。另stomp架構如下:

? ? ? ? ? ? ? ? ? ? ? ?(spring 官方圖片)

6. support模塊

提供了Message的實現,及創建消息的MessageBuilder和獲取消息頭的MessageHeaderAccessor,還有各種不同的MessageChannel實現和channel interceptor支持。

7. tcp模塊

? ?一方面提供了通過TcpOperations建立tcp connection、通過TcpConnectionHandler處理消息和通過TcpConnectionf發送消息的抽象及實現;另一方面包含了對基于Reactor的tcp 消息支持。

8 小結

?Spring Framework 4 包含了一個新的spring-messaging?模塊,該模塊從使用了?Spring Integration?工程的核心概念如?Message,?MessageChannel,MessageHandler和別的一些可以作為消息架構的基礎組件。這個模塊同樣也提供了一些映射消息到方法的注解,類似于基于編程模型的spring mvc注解。

轉載于:https://www.cnblogs.com/davidwang456/p/4446796.html

總結

以上是生活随笔為你收集整理的spring源码分析之spring-messaging模块详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。