【问题标题】:Batching the send operation on outbound adapter in Spring Integration在 Spring Integration 中批处理出站适配器上的发送操作
【发布时间】:2015-09-23 02:17:54
【问题描述】:
我在 Spring 集成流程结束时有一个出站通道适配器(在本例中是 SFTP,但对于 JMS 或 WS 将是相同的)。通过在每次有消息流时使用直接通道,它将同步发送出去。
现在,我需要一直处理消息,直到它们到达出站适配器,但在发送它们之前等待预定的时间间隔。换句话说,批处理发送操作。
我知道 Spring Batch 项目可能会为此提供解决方案,但我需要使用 Spring Integration 组件(在 int-* 命名空间中)找到解决方案
实现这一目标的典型模式是什么?
【问题讨论】:
标签:
spring-batch
spring-integration
spring-jms
【解决方案1】:
Aggregator pattern 是给你的。
在您的特定情况下,我将其称为 window,因为您与群组消息没有任何特定关联,但只需要构建一个您所称的 batch。
所以,我认为您的聚合器配置可能如下所示:
<int:aggregator input-channel="input" output-channel="output"
correlation-strategy-expression="1"
release-strategy-expression="size() == 10"
expire-groups-upon-completion="true"
send-partial-result-on-expiry="true"/>
-
correlation-strategy-expression="1" 表示 group 任何传入消息
-
release-strategy-expression="size() == 10" 允许通过 10 条消息形成和发布批次
-
expire-groups-upon-completion="true" 告诉聚合器从其存储中删除发布组。这允许为同一个correlationKey(在我们的例子中为1)创建一个新组
-
send-partial-result-on-expiry="true" 指定normal 释放操作(发送到output-channel)必须在我们没有足够的消息来构建整个批次(在我们的例子中为10)时在过期函数上完成。对于这些选项,请遵循上述文档。