首页 > 其他分享 >spring-messaging

spring-messaging

时间:2022-10-30 10:05:34浏览次数:58  
标签:spring message method 消息 interface messaging Message Annotation


概述

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

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

spring-messaging_java

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

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

converter

spring-messaging_java_02

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。

spring-messaging_消息处理_03

support

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

tcp

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

参考

​官方文档​

​spring-messaging模块详解


标签:spring,message,method,消息,interface,messaging,Message,Annotation
From: https://blog.51cto.com/u_15851118/5807190

相关文章

  • springBoot
    入门案例:直接开发控制器的类: 4.运行自带的带有main方法的类  SpringBoot能运行的原因是,在pom里面继承了一个依赖,父类里面有很多依赖,还有一个启动依赖,里......
  • Spring源码-SpringMVC-搭建springmvc环境
    一、新建模块myself-web新建gradle的web项目,右键项目名,选择NEW-Moudle.左边选择Gradle,右下选择web即可。build.gradleplugins{id'java'id'war'id"com.bmuschko......
  • 十三,SpringBoot-全局异常处理器
     springboot自定义拦截器,需要继承WebMvcConfigurerAdapter并重写addInterceptors。======以下仅为示例,代码沿用上一章=====具体实现如下:①创建MyInterceptor.java文件@Conf......
  • 解决SpringBoot测试提示Failed to resolve org.junit.platform:junit-platform-launch
    解决SpringBoot测试提示Failedtoresolveorg.junit.platform:junit-platform-launcher:1.5.2解决方案:只需要添加:junit-platform-launcher依赖即可<dependency>......
  • Springboot项目启动报错Failed to configure a DataSource: ‘url‘ attribute is not
    ***************************APPLICATIONFAILEDTOSTART***************************Description:FailedtoconfigureaDataSource:'url'attributeisnotspecified......
  • SpringMVC_day02
    SpringMVC_day02今日内容完成SSM的整合开发能够理解并实现统一结果封装与统一异常处理能够完成前后台功能整合开发掌握拦截器的编写1,SSM整合前面我们已经把Myba......
  • SpringMVC_day01
    SpringMVC_day01今日内容理解SpringMVC相关概念完成SpringMVC的入门案例学会使用PostMan工具发送请求和数据掌握SpringMVC如何接收请求、数据和响应结果掌握RESTfu......
  • Spring注解之@Value基于Apollo或者YAML文件为静态变量赋值
    摘要:SpringBoot微服务中,把在Apollo配置中心或者YAML文件里配置的属性赋值给静态变量。综述  Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同......
  • Springboot + bootstrap 实现 增删改查
    SpringBoot+bootstrap 配合mysql实现增删改查功能创建项目打开idea工具----  点击File---new---Project创建springBoot项目工程,版本统一:我使......
  • SpringBoot推送微信测试公众号信息
    1、登陆微信公众平台测试号2、扫码关注3、新建模版参数需以{{开头,以.DATA}}结尾,ex:{{msg.DATA}},代码里面替换就可以了templateMessage.addData(newWxMpTemplateDat......