0

尝试使用 spring-integration-file 使用单个出站网关将文件放在多个目录中。我知道这样的通道适配器不可能一次发送到多个目录。

为了实现这一点,在 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>
4

1 回答 1

2

你不需要<integration:gateway request-channel="filesOutChainChannel"在你的链的末端有一个。你应该只配置一个链来输出到filesOutChainChannel过滤器中,看起来你做了正确的事情。

它等待回复的网关的问题,但是由于您将其循环到filesHeaderEnricherChannel后面,您会一次又一次地使用等待网关来增加调用堆栈。

于 2018-11-12T14:37:54.737 回答