Spring集成文件入站适配器扫描目录每个轮询

时间:2018-01-24 06:19:29

标签: spring-integration

我想增强我当前的文件入站通道适配器,它将扫描目录以刷新队列中的文件列表以进行每次轮询。

以下是我当前文件入站通道适配器的XML配置:

<int-file:inbound-channel-adapter id="hostFilesOut" channel="hostFileOutChannel"
    directory="${hostfile.dir.out}" prevent-duplicates="false"
    filename-regex="${hostfile.out.filename-regex}" >
    <int:poller id="poller" cron="${poller.cron:0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * * }"
        max-messages-per-poll="1" />
</int-file:inbound-channel-adapter> 

我尝试创建自定义扫描程序来读取文件。但是,将扫描程序用于文件入站通道适配器将导致cron配置无法正常工作。

有人可以就此提出建议,还是有其他办法也可以达到同样的目标。

谢谢。

1 个答案:

答案 0 :(得分:1)

FileReadingMessageSource已有这样一个选项:

/**
 * Optional. Set this flag if you want to make sure the internal queue is
 * refreshed with the latest content of the input directory on each poll.
 * <p>
 * By default this implementation will empty its queue before looking at the
 * directory again. In cases where order is relevant it is important to
 * consider the effects of setting this flag. The internal
 * {@link java.util.concurrent.BlockingQueue} that this class is keeping
 * will more likely be out of sync with the file system if this flag is set
 * to <code>false</code>, but it will change more often (causing expensive
 * reordering) if it is set to <code>true</code>.
 *
 * @param scanEachPoll
 *            whether or not the component should re-scan (as opposed to not
 *            rescanning until the entire backlog has been delivered)
 */
public void setScanEachPoll(boolean scanEachPoll) {

但令我感到惊讶的是,我们没有为XML配置公开该选项,尽管该选项自第一天开始就存在https://jira.spring.io/browse/INT-583

这是关于此问题的Doc

作为一种解决方法,您可以创建FileReadingMessageSource bean并将其用作ref中的<int:inbound-channel-adapter>。另一种继续的方法是Annotations或Java DSL配置。您可以在上面提到的Doc中找到一些示例。

对于XML支持,请提出一个JIRA,我们将添加这样一个XSD定义。也不要犹豫为此事做出贡献!

相关问题