此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1spring-doc.cadn.net.cn

聚合器和重排序器

Aggregator在概念上与Splitter. 它将一系列单个消息聚合到单个消息中,并且必然更加复杂。 默认情况下,聚合器返回一条消息,其中包含来自传入消息的有效负载集合。 相同的规则适用于Resequencer. 以下示例显示了拆分器聚合器模式的规范示例:spring-doc.cadn.net.cn

@Bean
public IntegrationFlow splitAggregateFlow() {
    return IntegrationFlow.from("splitAggregateInput")
            .split()
            .channel(MessageChannels.executor(this.taskExecutor()))
            .resequence()
            .aggregate()
            .get();
}

split()方法将列表拆分为单独的消息,并将它们发送到ExecutorChannel. 这resequence()方法按消息头中的序列详细信息对消息重新排序。 这aggregate()方法收集这些消息。spring-doc.cadn.net.cn

但是,您可以通过指定发布策略和关联策略等来更改默认行为。 请考虑以下示例:spring-doc.cadn.net.cn

.aggregate(a ->
        a.correlationStrategy(m -> m.getHeaders().get("myCorrelationKey"))
            .releaseStrategy(g -> g.size() > 10)
            .messageStore(messageStore()))

前面的示例关联了具有myCorrelationKey标头并在累积至少十个消息后释放消息。spring-doc.cadn.net.cn

resequence()EIP 方法。spring-doc.cadn.net.cn