代码之家  ›  专栏  ›  技术社区  ›  Makky

SpringIntegration轮询器复制文件

  •  2
  • Makky  · 技术社区  · 6 年前

    我已经设置了任务执行器的文件轮询器

    ExecutorService executorService = Executors.newFixedThreadPool(10);
    
                LOG.info("Setting up the poller for directory {} ", finalDirectory);
                StandardIntegrationFlow standardIntegrationFlow = IntegrationFlows.from(new CustomFileReadingSource(finalDirectory),
                        c -> c.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS, 5)
                                .taskExecutor(executorService)
                                .maxMessagesPerPoll(10)
                                .advice(new LoggerSourceAdvisor(finalDirectory))
                        ))
    
    
                        //move file to processing first processing                    
                        .transform(new FileMoveTransformer("C:/processing", true))
                        .channel("fileRouter")
                        .get();
    

    我使用的是基于AcceptOnceFilter的lastUpdated。

    它的所有工作良好的问题,我有一个目录,我投票的文件来自外部系统。文件仍在被复制,应用程序提取并处理部分数据。

    如何在处理之前确保文件已完全写入。

    我无法更改外部系统,因为他们只是将文件复制到文件夹中。他们不会改变他们的制度。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Artem Bilan    6 年前

    AcceptOnceFileListFilter LastModifiedFileListFilter 让这些文件在您开始读取它们之前在目录中保留一段时间。所以,在你拿起它们之前,它们可能已经写好了。

    有关详细信息,请参阅文档: https://docs.spring.io/spring-integration/reference/html/files.html#file-reading

        2
  •  1
  •   Community CDub    4 年前

    如何在处理之前确保文件已完全写入。

    我们提供 LastModifiedFileListFilter ; 您也可以监视文件大小,但不管怎样,这都是一种脆弱的技术,因为网络故障可能会导致文件传输暂停。另外,在复制文件时更新这些属性也取决于操作系统(和远程访问机制),这种情况可能并不总是这样。