【问题标题】:Spring SFTP polling multiple directory using Outbound Message Gateway and IntegrationFlowSpring SFTP 使用出站消息网关和 IntegrationFlow 轮询多个目录
【发布时间】: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


【解决方案1】:

.filter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "autoscore-meta-data"))) 使其工作方式不会在随后的投票活动中一次又一次地拾取同一个文件。

确保在运行时在该远程目录中添加新文件或修改已处理的文件。 SftpPersistentAcceptOnceFileListFilter 逻辑依赖于LsEntrymtime 属性来确定文件已被更改,因此可以再次处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 2016-01-09
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多