Spring 如何聚合来自多个渠道的响应
我有一个包含以下内容的spring集成实现:Spring 如何聚合来自多个渠道的响应,spring,spring-integration,spring-integration-dsl,Spring,Spring Integration,Spring Integration Dsl,我有一个包含以下内容的spring集成实现: 多个发布通道在一个公共通道上发布 所有通道返回相同的响应对象 聚合器正在尝试聚合来自上述所有通道的响应 问题:聚合器无法将所有响应组合在一起,并且提供的方法在来自通道的第一次响应时被调用 详情如下。我需要做些什么来聚合响应 <int:publish-subscribe-channel id="aggregate-channel" apply-sequence="true"/> <int:pub
<int:publish-subscribe-channel id="aggregate-channel" apply-sequence="true"/>
<int:publish-subscribe-channel id="input-channel" apply-sequence="true"/>
<int:service-activator input-channel="input-channel" output-channel="aggregate-channel" ref="...A" method="...A">
<int:service-activator input-channel="input-channel" output-channel="aggregate-channel" ref="...B" method="...B">
<int:service-activator input-channel="input-channel" output-channel="aggregate-channel" ref="...C" method="...C">
<int:service-activator input-channel="input-channel" output-channel="aggregate-channel" ref="...D" method="...D">
<!--This is the aggregator.
**Expecting a list of size 4 but then it gets list of size 1 for each response channel
-->
<int:aggregator input-channel="aggregate-channel" output-channel="gateway-response-channel" ref="Service" method="responseListProcessor"/>
解决方案
- 替换
问题
- 最初它以序列大小
开始,因为4
具有input channel
订户4
- 但是,当您将属性
添加到apply sequence=“true”
时,它会将序列大小重置为聚合频道
,因为1
只有一个订户,即聚合频道
聚合器
我想说,对于这类任务,EIP-分散-聚集的特定任务完全涵盖了您的需求:spring integration在使用聚合器组合的频道上应用序列=true时处理关联策略和发布策略。我正在尝试使用开箱即用的实现。做了一些小的修改,检查一下。我已经让它工作了。如果将
apply sequence=“true”
从aggregate channel
中删除,则它会将4条消息批处理在一起,因为您有4个订阅方订阅input channel
responseListProcessor,并根据自定义业务逻辑检查流程输入列表以发送网关响应。
<int:publish-subscribe-channel id="aggregate-channel" apply-sequence="true"/>
with
<int:publish-subscribe-channel id="aggregate-channel"/>