春季集成:分散收集,并行Web服务调用后收集不起作用

时间:2019-07-09 23:57:49

标签: spring-integration scatter

我正在设置spring集成流程,以使用来自MQ的消息,并通过创建从MQ Messages创建的请求来并行调用Web服务调用。

下面是弹簧集成流程的样子

  • 使用来自IBM MQ的消息,使用Marshaller转换消息并将实体保存到DB。
  • 将保存的实体发送到分散收集通道。
  • 分散聚集通道有两个分配通道,每个分配通道都是由以下部分组成的链

    1. Web服务客户端以进行Web服务调用(服务激活器)
    2. 将响应转换为实体对象的变压器
    3. 将数据保存到数据库的处理程序。
  • 收集来自并行Web服务调用的响应,并将通过两个并行Web服务调用创建的新对象发送到RabbitMQ。

我能够从散布式聚集模式进行并行Web服务调用,但是我看不到聚集模式中发生聚合,基本上流没有进入聚集器类。

我尝试了使用任务执行器作为发布-收集模式的输入通道的Publish-Subscribe通道,并且根据日志,Web服务调用与两个任务执行器并行发生,但是在Web服务调用之后它从未到达收集器。

<si:service-activator input-channel="transformedEntity"
        ref="incidentHandler" output-channel="outputChannelFromMQ" />

<si:scatter-gather input-channel="outputChannelFromMQ" 
        requires-reply="false" output-channel="gatherResponseOutputChannel" gather-channel="gatherChannel" gather-timeout="4000">
        <si:scatterer apply-sequence="true">
            <si:recipient channel="distributionChannel1" />
            <si:recipient channel="distributionChannel2" />
        </si:scatterer>         
</si:scatter-gather>

<si:publish-subscribe-channel id="outputChannelFromMQ" apply-sequence="true" 
        task-executor="taskExecutor" />

<task:executor id="taskExecutor" queue-capacity="25"    pool-size="10-10" />

<si:chain id="planngedBagsChain" input-channel="distributionChannel1"
        output-channel="gatherChannel">
    <si:service-activator ref="webServiceClient1" method="getResponse" />
    <si:service-activator ref="serviceHandler1"     method="saveToDB" />
</si:chain>

<si:chain id="bagHistoryChain" input-channel="distributionChannel2"
    output-channel="gatherChannel">
    <si:service-activator ref="webServiceClient2" method="getResponse" />
    <si:transformer ref="transformer" />
    <si:service-activator ref="serviceHandler2" method="saveToDB" />
</si:chain>

<si:service-activator input-channel="gatherResponseOutputChannel"
    ref="responseTransformer" method="receiveResponse" output-channel="toRabbitMQ" />

1 个答案:

答案 0 :(得分:0)

启用调试日志后,便能够找出将其发送到的所有通道。通过上述配置,它不会正确地收集到。更改为以下配置即可。

<si:service-activator input-channel="transformedEntity"
        ref="incidentHandler" output-channel="outputChannelFromMQ" />

<si:channel id="outputChannelFromMQ"></si:channel>

<si:scatter-gather input-channel="outputChannelFromMQ"
         requires-reply="false" scatter-channel="scatterInputChannel" output-channel="toRabbit"  
         gather-channel="gatherChannel" gather-timeout="4000">
        <si:gatherer id="responseGatherer"  ref="responseTransformer" release-strategy-expression="size() == 2"/>
    </si:scatter-gather>

<si:publish-subscribe-channel id="scatterInputChannel" apply-sequence="true" 
        task-executor="taskExecutor" />

<task:executor id="taskExecutor" queue-capacity="25"    pool-size="10-10" />

<si:chain id="planngedBagsChain" input-channel="scatterInputChannel"
        output-channel="gatherChannel">
    <si:service-activator ref="webServiceClient1" method="getResponse" />
    <si:service-activator ref="serviceHandler1"     method="saveToDB" />
</si:chain>

<si:chain id="bagHistoryChain" input-channel="scatterInputChannel"
    output-channel="gatherChannel">
    <si:service-activator ref="webServiceClient2" method="getResponse" />
    <si:transformer ref="transformer" />
    <si:service-activator ref="serviceHandler2" method="saveToDB" />
</si:chain>