spring-messaging

概述

Spring框架作为Java开源世界的集大成者,

spring-messaging模块为集成messaging api和消息协议提供支持。

在这里插入图片描述

其代码结构为:包括base、converter、core、handler、simp、support、tcp
其中base定义消息Message(MessageHeader和body)、消息处理MessageHandler、发送消息MessageChannel。

message由两部分组成,header & payload;
MessageHandler是一个处理消息的约定,spring messaging提供丰富的消息处理方式。
MessageChannel表现为pipes-and-filters架构的管道。

converter

在这里插入图片描述

public abstract class AbstractMessageConverter implements SmartMessageConverter {
    @Nullable
    private ContentTypeResolver contentTypeResolver;
}

有消息到string、json、byte数组之间的相互转换。

core

核心模块提供消息的模板方法,

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.

rsocket

simp

包含诸如STOMP协议的简单消息协议的通用支持。

STOMP,Streaming Text Orientated Message Protocol,是流文本定向消息协议,是一种为MOM(Message Oriented Middleware,面向消息的中间件)设计的简单文本协议。它提供一个可互操作的连接格式,允许STOMP客户端与任意STOMP消息代理(Broker)进行交互,类似于OpenWire(一种二进制协议)。由于其设计简单,很容易开发客户端,因此在多种语言和多种平台上得到广泛应用。其中最流行的STOMP消息代理是Apache ActiveMQ。

在这里插入图片描述

support

提供Message的实现,及创建消息的MessageBuilder和获取消息头的MessageHeaderAccessor,还有各种不同的MessageChannel实现和channel interceptor支持。

tcp

一方面提供通过TcpOperations建立tcp connection、通过TcpConnectionHandler处理消息和通过TcpConnectionf发送消息的抽象及实现;另一方面包含对基于Reactor的tcp 消息支持。

参考

官方文档
spring-messaging模块详解

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

johnny233

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值