在ftp适配器成功处理原始文件时重命名原始文件

时间:2017-03-01 13:36:08

标签: spring-integration

我有以下Spring Integration配置:

@Bean
public IntegrationFlow myFlow() {
    return IntegrationFlows.from(Files.inboundAdapter(new File(inputDir))
                    .patternFilter("*.csv"),
            poller -> poller.poller(pm -> pm.cron(cronExpression)))
            .transform(Transformers.fileToByteArray())
            .handleWithAdapter(adapters -> adapters.ftp(ftpSessionFactory())
                    .remoteDirectory(remoteDir))
            .get();
} 

它工作正常但是如何在ftp适配器成功时重命名原始文件以将其标记为已处理?

1 个答案:

答案 0 :(得分:1)

这可以使用ExpressionEvaluatingRequestHandlerAdvice来完成。在xml配置中,它看起来像:

<int-ftp:outbound-channel-adapter
    channel="inputChannel"
    session-factory="mockSessionFactory"
    remote-directory="foo">
    <int-ftp:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpression" value="payload.delete()" />
            <property name="successChannel" ref="afterSuccessDeleteChannel" />
            <property name="onFailureExpression" value="payload.renameTo(new java.io.File(payload.absolutePath + '.failed.to.send'))" />
            <property name="failureChannel" ref="afterFailRenameChannel" />
        </bean>
    </int-ftp:request-handler-advice-chain>
</int-ftp:outbound-channel-adapter>