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

我有一个包含以下内容的spring集成实现:

  • 多个发布通道在一个公共通道上发布
  • 所有通道返回相同的响应对象
  • 聚合器正在尝试聚合来自上述所有通道的响应
  • 问题:聚合器无法将所有响应组合在一起,并且提供的方法在来自通道的第一次响应时被调用

    详情如下。我需要做些什么来聚合响应

    <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
      ,因为
      聚合频道
      只有一个订户,即
      聚合器
    参考

    如果提供PublishSubscribeChannel下游的聚合器,则可以将通道上的“应用序列”属性设置为true

    这样做表明通道应该在传递消息之前设置序列大小和序列号消息头以及相关ID

    例如,如果有五个订阅者,则序列大小将设置为5,消息的序列号标头值范围为1到5


    我想说,对于这类任务,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"/>