java - Spring 集成 - 如何在不轮询的情况下检查文件目录?

标签 java spring file spring-integration dsl

spring 集成中是否有一种方法(使用 int-file:inbound-channel-adapter 或任何其他方式)简单地检查目录中的文件(最好是模式匹配)而不进行轮询,如果文件存在,则获取它并进一步处理,如果没有,只需退出(我可以使用路由器进行条件重定向)..我想要实现的是基于简单的一次性文件检查来控制流量,而不是像轮询目录一样一个文件观察者。或者我必须使用服务激活器在 Java 中完成吗?

编辑:

这是我目前所得到的:

@Bean
    public FileReadingMessageSource fileSource();
    CompositeFileListFilter f=new CompositeFileListFilter();
    f.addFilter(new SimplePatternFileListFilter("*.zip"));
    FileReadingMessageSource fsource = new FileReadingMessageSource();
    fsource.setDirectory(inputDir);
    fsource.setFilter(f);
    return fsource;
}

@Bean
    public IntegrationFlow loadInput(){
        return IntegrationFlows
                .from(fileSource())
//                .from(Files.inboundAdapter(inputDir)
//                                .patternFilter("*.zip"),
//                        e -> e.poller(Pollers
//                                .fixedDelay(20000)
//                                .maxMessagesPerPoll(1)))
                .handle("inputLoaderService", "extractZip")
                .handle("inputLoaderService", "readInputFile")
                .enrichHeaders(s -> s.header("Content-Type", "application/json"))
                .channel("requestChannel")
                .get();
    }

能否请您指导我如何正确接线?塔!

最佳答案

您可以连接一个 FileReadingMessageSource bean 并调用它的 receive() 方法。当没有剩余文件时,它将返回 null。

关于java - Spring 集成 - 如何在不轮询的情况下检查文件目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31845269/

相关文章:

java - 如何将属性添加到 spring Controller 的 http 请求?

java - 在 Eclipse 中导入 HoloEverywhere 和 ActionbarSherlock 的属性复制

java - Clojure 和 Java 之间的界限在哪里?

c - 从文件中逐字读取或一次读取一行并使用 C 拆分字符串更有效率?

ios - NSDirectoryEnumerator fileAttributes 为 nil

python - 如何从文件夹中随机选择一个文件而不将所有文件读取到内存

java - 加快 Java 开发速度

java - RetryCallback 类型的参数数量不正确

java - Spring WebService无效的NamespaceHandler问题(JAXWS)

java - HibernateJPAVendorAdapter 和 JPAProperty 中的属性之间的优先级