我有以下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适配器成功时重命名原始文件以将其标记为已处理?
答案 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>