0

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.

ash
  • 156
  • 3
  • 12
  • 1
    `>after the outChannel is complete` you need to explain what you mean by that. If it' a flow that returns a reply; move 6 and 7 to another chain. If it runs some code on the same thread, but returns no reply; add a `` between 5 and 6 with a 0 reply timeout, to send to the `outChannel`; 6 and 7 will then run; but you need to decide what to do with the output of 7. Currently, it will also go to the outChannel. – Gary Russell Mar 20 '23 at 13:13
  • @GaryRussell Thanks for your insight. `outChannel` is a flow which ends into `nullChannel` and returns no reply. I do not think `` would be an option since I want to execute 6 and 7 only on successful completion of `outChannel` flow. – ash Mar 20 '23 at 18:33
  • And what about 7's output? If the subflow on the `` throws an exception, 6 and 7 won't be called. – Gary Russell Mar 20 '23 at 18:36
  • @GaryRussell Need to end the flow after 7. Maybe use a `nullChannel`? Can you please let me know if I use `` after 5, would 6 and 7 wait until the `outChannel` flow is completed? – ash Mar 20 '23 at 18:41

1 Answers1

1

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).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks @Gary Russell. I also came across this https://docs.spring.io/spring-integration/reference/html/gateway.html#long-running-process-downstream Since my application is single threaded, your suggestion should work. I will soon implement and confirm. – ash Mar 20 '23 at 18:55