【问题标题】:Spring Integration File Inbound Adapter Scan Directory Each PollSpring集成文件入站适配器扫描目录每次轮询
【发布时间】:2018-01-24 06:19:28
【问题描述】:

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

以下是我当前文件入站通道适配器的 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 配置不起作用。

有人可以就此提出建议还是有其他方法也可以实现相同的目标。

谢谢。

【问题讨论】:

  • 你的问题不清楚。为什么您认为添加自定义扫描器会阻止轮询器工作?他们是无关的。我建议你打开 DEBUG 日志记录。
  • 另见我的回答。

标签: spring-integration


【解决方案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 并将其用作 &lt;int:inbound-channel-adapter&gt; 中的 ref。另一种方法是注解或 Java DSL 配置。您可以在上面提到的 Doc 中找到一些示例。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多