Spring集成-如何在不轮询的情况下检查目录中的文件? [英] Spring integration - how to check a directory for files, without polling?

查看:64
本文介绍了Spring集成-如何在不轮询的情况下检查目录中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way in spring integration, (either using int-file:inbound-channel-adapter or any other means) to simply check a directory for file (preferably pattern match) without polling and if file exists, fetch it and process further and if it doesn't, simply quit (i can use routers for conditional redirects) .. the thing i'm trying to achieve is to control the flow based on a simple once-off file check instead of polling the directory like a file-watcher. OR will I have to do it in Java, using a service activator?

编辑:

这是到目前为止我得到的:

This is what I've got so far:

@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();
    }

请指导我如何正确接线? Ta!

Could you please guide me as to how I can get this properly wired? Ta!

推荐答案

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

You can wire up a FileReadingMessageSource bean and call its receive() method. When there are no files remaining, it will return null.

这篇关于Spring集成-如何在不轮询的情况下检查目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆