读取通配符文件名的 Quartz 作业只获取一个文件

Quartz job to read wildcard filename only picks up one file

使用 Mule 3.7。如果我在扩展名为 .csv 的目录中有 5 个文件,则以下代码只会选取这五个文件之一。如果我移除石英触发器并将其设为正常的 file:inbound-endpoint,它会拾取所有五个文件。看起来很简单,但并不像预期的那样工作。
谢谢,
-- 唐

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:context="http://www.springframework.org/schema/context" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz"
    xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <file:connector name="fileInConnector" autoDelete="false" streaming="true" validateConnections="true" doc:name="FileConnector" />
    <file:endpoint name="fileInEndpoint" path="\\c:\scratch" connector-ref="fileInConnector" doc:name="FileEndpoint">
        <file:filename-wildcard-filter pattern="*.csv" />
    </file:endpoint>
    <flow name="fileUploader">
        <quartz:inbound-endpoint jobName="getFilesTrigger" cronExpression="/15 * * * * ?" doc:name="Quartz">
            <quartz:endpoint-polling-job>
                <quartz:job-endpoint ref="fileInEndpoint" />
            </quartz:endpoint-polling-job>
        </quartz:inbound-endpoint>
        <logger message="Filename=#[message.inboundProperties.originalFilename]" level="INFO" doc:name="Logger" />
    </flow>
</mule>  

这是触发两次后的日志:
信息 2015-10-05 15:09:30,063 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager:正在初始化:'fileInConnector.requester.2009817243'。对象是:FileMessageRequester
信息 2015-10-05 15:09:30,069 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager:开始:'fileInConnector.requester.2009817243'。对象是:FileMessageRequester
信息 2015-10-05 15:09:30,117 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: 文件名=D1.csv
信息 2015-10-05 15:09:45,015 [scheduler-quartzcronfilepickup_Worker-2] org.mule.lifecycle.AbstractLifecycleManager:正在初始化:'fileInConnector.requester.636902426'。对象是:FileMessageRequester
信息 2015-10-05 15:09:45,016 [scheduler-quartzcronfilepickup_Worker-2] org.mule.lifecycle.AbstractLifecycleManager:开始:'fileInConnector.requester.636902426'。对象是:FileMessageRequester
信息 2015-10-05 15:09:45,022 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: 文件名=D1.csv

使用轮询文件入站端点和 Quartz 入站端点轮询文件端点之间存在主要区别:前者使用消息接收器,而后者使用消息请求者。作为两种不同的野兽,它们有可能以完全不同的方式实现。

而且,您猜怎么着?文件正是这种情况。文件消息接收者uses a lock mechanism to prevent polling a file that is being processed, while the requester does not.

有趣的是请求者源代码中的注释:

// Don't we need to try to obtain a file lock as we do with receiver

请求者的这种怀疑和锁定使用的缺乏是导致它的行为与接收者不同的原因。这个问题从未得到肯定解决的事实可能意味着在那里添加锁会产生不良副作用。

无论如何,如果您坚持使用Quartz,我建议您将正在处理的文件移动到另一个目录,以防止重新轮询。文件端点应该能够为您完成移动。