Looping channel to update the header enricher to place file in multiple targets

215 views Asked by At

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>
1

There are 1 answers

4
Artem Bilan On BEST ANSWER

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.