我想增强我当前的文件入站通道适配器,该适配器将扫描目录以刷新每次轮询队列中的文件列表。
以下是我当前文件入站通道适配器的 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 配置不起作用。
有人可以对此提出建议,或者是否有任何其他方法也可以实现相同的目标。
谢谢。
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 就存在。
这是关于此事的文档。
作为一种解决方法,您可以创建FileReadingMessageSource
bean 并将其用作 <int:inbound-channel-adapter>
中的ref
。另一种方法是注释或Java DSL配置。您可以在上面提到的文档中找到一些示例。
对于XML支持,请提出JIRA,我们将添加这样的XSD定义。也不要犹豫,为此事做出贡献!