0

Trying to place a file in multiple directories using single outbound gateway using spring-integration-file.I Know that it's not possible with such a channel adapter to send to several directories at a time.

In order to achieve that, having a loop in front of the file:outbound-gateway to modify message header target directory on each iteration and send all of them to the same channel again and again.

But getting exception as mentioned below.

Any suggestion how to loop it or update the header and execute the adapter again

file : Outbound gateway:

<!-- header enricher -->
    <integration:header-enricher input-channel="filesHeaderEnricherChannel" output-channel="filesOut">
       <integration:header name="TARGET_COUNT" method="getTargetCount" ref="headerEnricher"/>
            <integration:header name="TARGET_DIR" method="getTargetPath" ref="headerEnricher"/>     
    </integration:header-enricher>

    <integration:chain id="filesOutChain" input-channel="filesOut">
        <integration:transformer expression="headers.FILE"/>
            <file:outbound-adapter id="fileMover" 
                auto-create-directory="true"
                directory-expression="headers.TARGET_DIR"
                mode="REPLACE">
                <file:request-handler-advice-chain>
                    <ref bean="retryAdvice" />
                </file:request-handler-advice-chain>
            </file:outbound-adapter>    
       </integration:chain> 

<!-- decreasing the count on each loop -->
<!-- looping to header enricher channel again as output channel to update the target directory -->
           <integration:filter input-channel="filesOut"  expression="headers.TARGET_COUNT != 0" output-channel="filesHeaderEnricherChannel"
                    discard-channel="filesArchiveChannel" throw-exception-on-rejection="true">
                    <integration:request-handler-advice-chain>
                    <ref bean="retryAdvice" />
                    </integration:request-handler-advice-chain>
        </<integration:filter>
Jessie
  • 963
  • 5
  • 16
  • 26

1 Answers1

2

You don't need to have a <integration:gateway request-channel="filesOutChainChannel" in the end of your chain. you should just configure a chain to output into the filesOutChainChannel and there in the filter it seems you do right things.

The problem with the gateway that it waits for reply, but since you loop it into the filesHeaderEnricherChannel back you grow the call stack with with waiting gateways again and again.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • have tried your solution. am not getting the call stack exception now after replaced the gateway with adapter. But the call doesnot go back to the loop "filesHeaderEnricherChannel". attached edited code above for your reference. – Jessie Nov 13 '18 at 15:39
  • Looks like you didn't understand me and did a big mistake in your config. Now you have to round-robin subscribers on the `filesOut` channel. My point was to have an `outpup-channel` on the chain, however I see you have changed a gateway to the ` `, so you are not going to wait for reply. That's fine too. so, consider to make that `filesOut` as ``. Also not sure why do you need a `retryAdvice` on that filter... – Artem Bilan Nov 13 '18 at 16:30
  • Am sorry. Got your point now. Asked me to add output - channel for integration:chain...will try it...just need a confirmation...after adding...will it loop back to "filesHeaderEnricherChannel"...is it possible to do loop back to channel which is above the code? – Jessie Nov 13 '18 at 16:39
  • That's fully doesn't matter: in the end you have some objects in the memory you interact with. The config is fully not related there at all. – Artem Bilan Nov 13 '18 at 16:40