• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Spring Integration-Message Endpoints概念

武飞扬头像
EngineZhang
帮助1

Message Endpoints概念介绍

Spring Integration是基于管道-过滤器架构的,Message Endpoint是过滤器中的一部分。在简介中提到过,endpoint主要是用来关联框架与应用业务代码的,就像MVC模型中controller只需要与url绑定即可获取到请求数据进行业务处理一样,endpoint只需要与message channel进行映射即可。

这里将与同学们共同学习Spring Integration提供的一些Endpoint类型。

Message Transformer

消息转换器用于转换消息内容及消息结构体,可以对消息内容进行修改。如:报文格式转化(JSON-XML互转),报文格式化,数据脱敏,报文头修改等。

Message Filter

消息过滤器用于处理消息是否需要传递,可以用来进行权限及认证控制、限流控制等。

Message Router

消息路由器用于决定消息下一步发送到哪个通道,一般根据报文内容或消息元数据来确定。
学新通

Splitter

分流器可以将一个消息分成多个消息,并且可以将这些消息分发给不同的输出通道。

Aggregator

聚合器与分流器相反,用于将多个消息聚合为一个消息,但是聚合器要比分流器复杂的多,因为为了聚合不同的消息需要维护待聚合消息的状态,以此决定一组消息是否完成了聚合或者是否已经超时。Spring Integration提供了CorrelationStrategy和ReleaseStrategy两种策略、超时配置以及一个丢弃通道,用于决定当聚合超时候是否发送部分消息。

Service Activator

Service Activator用于调用service对象的方法,在调用过程中activator提取请求消息的payload作为参数去调用service的方法,当service方法有返回值时将会被封装成Message对象并发送到输出通道。因此在配置Service Activator时需要配置消息输入通道及消息输出通道(如果有返回值),如果没有配置输出通道,也可以通过消息头中的"Return Address"来指定输出通道。
学新通

Channel Adapter

Channel Adapter用来提供不同协议消息的适配。
学新通

Endpoint Bean Names

Endpoint有多种配置方式:

Service Activator:

<int:service-activator id = "someService" ... />
@Component
public class SomeComponent {
  @ServiceActivator(inputChannel = ...)
  public String someMethod(...) {
  ...
  }
}
@Component
public class SomeComponent {
  @EndpointId("someService")
  @ServiceActivator(inputChannel = ...)
  public String someMethod(...) {
  ...
  }
}
@Configuration
public class SomeConfiguration {
  @Bean
  @ServiceActivator(inputChannel = ...)
  public MessageHandler someHandler() {
  ...
  }
}
@Configuration
public class SomeConfiguration {
  @Bean("someService.handler") ①
  @EndpointId("someService") ②
  @ServiceActivator(inputChannel = ...)
  public MessageHandler someHandler() {
  ...
  }
}
学新通

Channel Adapter:

<int:inbound-channel-adapter id = "someAdapter" ... />
@EndpointId("someAdapter")
@InboundChannelAdapter(channel = "channel", poller = @Poller(fixedDelay = "5000" ))
public String pojoSource() {
  ... 
}
@Bean("someAdapter.source")
@EndpointId("someAdapter")
@InboundChannelAdapter(channel = "channel", poller = @Poller(fixedDelay = "5000" ))
public MessageSource<?> source() {
  return () -> {
  ...
  }; 
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfikfjk
系列文章
更多 icon
同类精品
更多 icon
继续加载