Search code examples
javaspringmessagespring-integrationduplicate-data

Spring Integration Parallel Processing without Aggreagation


I couldn't find enough/clear documentation on this.

I am getting a message from chain processing. Once the channel receives the message, I want to duplicate the message on conditional basis.

Simple flow:

<int-http:inbound-gateway request-channel="httpRequestChannel" reply-channel="httpResponseChannel" supported-methods="POST" 
    path="/doSomething" request-payload-type="com.xxx.Request" >
</int-http:inbound-gateway>

<int:chain id="msgChain" input-channel="httpRequestChannel" output-channel="processChannel">
    <int:claim-check-in message-store="messageStore"/>
    //do something
</int:chain>

<int:chain id="msgChain2" input-channel="processChannel" output-channel="parallelChannel">
    <int:claim-check-in message-store="messageStore"/>
    //do something
</int:chain>

<int:chain id="parallelChainId" input-channel="parallelChannel" output-channel="httpResponseChannel">
    <int:claim-check-in message-store="messageStore"/>
    if(payload infrom3rdparty property set i.e. payload.infrom3rdparty == true){
           send this message to //3party Channel
    }
    //do something
</int:chain>

I can't apply filter as discard-messages goes to different channel like if else. But I need just if duplicate message to another channel


Solution

  • Maybe you can try to use a publish-subscribe channel with 2 subscribers: - the standard flow to follow - the duplication flow

    On the duplication flow, you may use a filter to choose if a message should be send or not. It may be something like this:

    <int:publish-subscribe-channel id="parallelChannel"/>
    
    <int:chain id="standardFlowChain" input-channel="parallelChannel" output-channel="httpResponseChannel">
        <int:claim-check-in message-store="messageStore"/>
        //follow the standard flow
    </int:chain>
    <int:chain id="thirdPartyFlowChain" input-channel="parallelChannel" output-channel="thirdPartyOutputChannel">
        <int:claim-check-in message-store="messageStore"/>
        <int:filter expression="payload.infrom3rdparty == true"/>
    </int:chain>