【发布时间】:2021-12-08 17:24:40
【问题描述】:
我想定期获取特定远程目录下的所有文件。应用程序启动后,我只能在该目录下获取文件一次。不知道为什么轮询器不工作。这是在一个spring boot项目中注册的,版本是2.2.1
@InboundChannelAdapter(value = "sftpReportChannel",
poller = @Poller(fixedDelay = "5000"))
public String filesForGET(){
return "/etl/biq/autoscore/output/report-data/";
}
@Bean
public IntegrationFlow sftpGetFlow(SessionFactory<ChannelSftp.LsEntry> csf) {
return IntegrationFlows.from("sftpReportChannel")
.handle(Sftp.outboundGateway(csf,
AbstractRemoteFileOutboundGateway.Command.LS, "payload")
.options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE, AbstractRemoteFileOutboundGateway.Option.NAME_ONLY)
//Persistent file list filter using the server's file timestamp to detect if we've already 'seen' this file.
.filter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "autoscore-meta-data")))
.split()
.log(message -> "file path -> "+message.getPayload())
.handle(Sftp.outboundGateway(csf, AbstractRemoteFileOutboundGateway.Command.GET, "'/etl/biq/autoscore/output/report-data/' + payload")
.options(AbstractRemoteFileOutboundGateway.Option.STREAM))
.handle(new ReportHandler()) //get the payload and create email content and send eamil to recipients
.get();
}
【问题讨论】:
-
您确定在运行时将新文件添加到该目录中吗?你自己说的
SftpPersistentAcceptOnceFileListFilter。因此,不会从该目录中提取相同的文件。或者您可以修改该文件,远程文件的mtime应更改... -
感谢您的 cmets。很好的提示!是的,这就是原因。现在它工作正常。再次感谢您,它拯救了我的一天。
标签: spring-integration spring-integration-sftp