【发布时间】:2019-03-23 12:43:43
【问题描述】:
我有一个用例将文件传输到动态创建的某些子目录下的 sftp。 我使用自定义 SftpMessageHandler 方法和网关得到了这个工作。但是这种方法的问题是,它不会在成功上传后删除本地临时文件。 为了解决这个问题,现在我使用 IntegrationFlow 和表达式 Advice(如下所示),这确实删除了本地文件,但我不知道如何动态创建远程子目录。我阅读了远程目录表达式,但不确定如何使用/实现它。
有人解决了这个问题吗?任何帮助表示赞赏!
@Bean
public IntegrationFlow sftpOutboundFlow() {
return IntegrationFlows.from("toSftpChannel")
.handle(Sftp.outboundAdapter(this.sftpSessionFactory())
.remoteFileSeparator("/")
.useTemporaryFileName(false)
.remoteDirectory("/temp"), c -> c.advice(expressionAdvice(c)))
.get();
}
@Bean
public Advice expressionAdvice(GenericEndpointSpec<FileTransferringMessageHandler<ChannelSftp.LsEntry>> c) {
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setOnSuccessExpressionString("payload.delete()");
advice.setOnFailureExpressionString("payload + ' failed to upload'");
advice.setTrapException(true);
return advice;
}
@MessagingGateway
public interface UploadGateway {
@Gateway(requestChannel = "toSftpChannel")
void upload(File file);
}
【问题讨论】:
标签: spring-integration spring-integration-dsl spring-integration-sftp