Trying to place a file in multiple directories using single outbound adapter using spring-integration-file.
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 till the target count decreases to 0.
Able to loop back to the header enricher channel.but Since we are enriching the header value for the same header name again. the value is not getting updated for header name TARGET_DIR. There is no exception also.
Would like to know some solution if its possible to update the header value again and again for the same header name or is it possible to give the dynamic header name at runtime.
Have tried to delete the TARGET_DIR header using header:filter while looping back. But did not work out.
!-- 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" output-channel="filesOutChainChannel">
<integration:transformer expression="headers.FILE"/>
<file:outbound-channel-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-channel-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="filesOutChainChannel" expression="headers.TARGET_COUNT != 0" output-channel="filesHeaderEnricherChannel"
discard-channel="filesArchiveChannel">
</<integration:filter>
You are missing the fact that
header-enricher
has an extra option:As well as the sub-element
header
has its own:See also docs on the matter: https://docs.spring.io/spring-integration/docs/current/reference/html/message-transformation.html#header-enricher