石英作业读取通配符文件名只拾取一个文件



使用Mule 3.7。如果我在一个扩展名为.csv的目录中有5个文件,下面的代码只选取5个文件中的一个。如果我删除石英触发器并使其成为一个普通文件:入站端点,它将拾取所有五个文件。这看起来很简单,但并不像预期的那样工作。
谢谢你,
——

<?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>  

下面是它触发两次后的日志:
INFO 2015-10-05 15:09:30,063 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager:初始化:'fileInConnector.requester.2009817243'。对象是:FileMessageRequester
INFO 2015-10-05 15:09:30,069 [scheduler-quartzcronfilepickup_Worker-1] org. kernel .lifecycle. abstractlifecyclemanager: Starting: 'fileInConnector.requester.2009817243'。对象是:FileMessageRequester
INFO 2015-10-05 15:09:30,117 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Filename=D1.csv
INFO 2015-10-05 15:09:45,015 [scheduler-quartzcronfilepickup_Worker-2] org. kernel .lifecycle. abstractlifecyclemanager:初始化:'fileInConnector.requester.636902426'。对象是:FileMessageRequester
INFO 2015-10-05 15:09:45,016 [scheduler-quartzcronfilepickup_Worker-2] org. kernel .lifecycle. abstractlifecyclemanager: Starting: 'fileInConnector.requester.636902426'. .对象是:FileMessageRequester
INFO 2015-10-05 15:09:45,022 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Filename=D1.csv

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

你猜怎么着?,这正是文件的情况。文件消息接收者使用锁机制来防止轮询正在处理的文件,而请求者则不这样做。

有趣的是请求者源代码中的注释:
// Don't we need to try to obtain a file lock as we do with receiver

这种怀疑和请求程序中缺乏锁的使用是使请求程序的行为不同于接收程序的原因。事实上,这个问题从来没有得到解决,这可能意味着在那里添加锁会产生意想不到的副作用。

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

相关内容

最新更新