zoukankan      html  css  js  c++  java
  • 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 工程的核心概念如 MessageMessageChannel,MessageHandler和别的一些可以作为消息架构的基础组件。这个模块同样也提供了一些映射消息到方法的注解,类似于基于编程模型的spring mvc注解。

  • 相关阅读:
    【转】Aspose.Cells读取excel文件
    sencha treestore 取消自动加载数据
    百度地图js根据经纬度定位和拖动定位点
    sencha gridpanel checkbox 复选框的勾选 以及和单机行冲突
    c# tcp备忘及networkstream.length此流不支持查找解决
    小程序view排版
    .net+mvc,ueditor
    爬虫BS4—淘女郎
    爬虫手动流程
    python web cgi
  • 原文地址:https://www.cnblogs.com/davidwang456/p/4446796.html
Copyright © 2011-2022 走看看