ash
ash

Reputation: 156

How to get the flow back to current channel after output channel is processed in Spring Integration?

I have below channel defined in my spring integration xml.

<int:chain id="channel1" input-channel="inChannel" output-channel="outChannel">
        1. <int:service-activator method="logMessage" ref="commonHelper"/>
        2. <int:service-activator method="getAbcMessage" ref="flowHelper"/>
        3. <int:filter method="isApplicable" ref="flowHelper" discard-channel="nullChannel"/>
        4. <int-file:outbound-gateway directory="file:${archive-dir}" filename-generator="filenameGeneratorWithId" requires-reply="true" />
        5. <int:service-activator method="fetchInfo" ref="flowHelper"/>
        6. <int:service-activator method="batchMessage" ref="flowHelper"/>
        7. <int:service-activator method="logMessage" ref="commonHelper"/>
</int:chain>

I want to run line 1,2,3,4 and 5 and then send the message for processing into the outChannel and after the outChannel is complete, execute lines 6 and 7. Is this possible in Spring Integration? Please note that outChannel exists in imported xml file and that file must remain unchanged.

I have given a thought over Splitter and Router but I do not think it is achievable using those. Please correct me if I am wrong.

Upvotes: 0

Views: 102

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

Add a <gateway/> between 5 and 6 sending 5's output to outChannel; set the reply timeout to 0 since the gateway won't be returning a result.

As long as the subflow on outChannel uses only direct channels, 6 and 7 won't run until the thread returns normally from the gateway; if the subflow throws an exception, 6 and 7 won't run at all.

To end the flow after #7, set the chain's output channel to nullChannel (or leave it off althogether if logMessage is a void method - or returns null).

Upvotes: 1

Related Questions