问题描述
使用Mule 3.7.如果我的扩展名为.csv的目录中有5个文件,则下面的代码仅提取5个文件之一.如果删除石英触发器并将其设置为普通文件:入站端点,它将拾取所有五个文件.看起来很简单,但无法按预期工作.
谢谢,
-唐
Using Mule 3.7. If I have 5 files in a directory with a .csv extension the below code only picks up one of the five files. If I remove the quartz trigger and make it a normal file:inbound-endpoint it picks up all five files. It seems so simple but does not work as intended.
Thanks,
-- Don
<?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.mule.lifecycle.AbstractLifecycleManager:开始:"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.mule.lifecycle.AbstractLifecycleManager:初始化:"fileInConnector.requester.636902426".对象是:FileMessageRequester
INFO 2015-10-05 15:09:45,016 [scheduler-quartzcronfilepickup_Worker-2] org.mule.lifecycle.AbstractLifecycleManager:开始:"fileInConnector.requester.636902426".对象是:FileMessageRequester
INFO 2015-10-05 15:09:45,022 [[quartzcronfilepickup] .fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Filename = D1.csv
Here is the log after it firing twice:
INFO 2015-10-05 15:09:30,063 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'fileInConnector.requester.2009817243'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:30,069 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'fileInConnector.requester.2009817243'. Object is: 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.mule.lifecycle.AbstractLifecycleManager: Initialising: 'fileInConnector.requester.636902426'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:45,016 [scheduler-quartzcronfilepickup_Worker-2] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'fileInConnector.requester.636902426'. Object is: FileMessageRequester
INFO 2015-10-05 15:09:45,022 [[quartzcronfilepickup].fileUploader.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Filename=D1.csv
推荐答案
使用轮询文件入站端点和Quartz入站端点对文件端点进行轮询之间存在主要区别:前者使用消息接收器,而后者使用消息请求者.作为两种不同的野兽,它们有可能以完全不同的方式实施.
There is a major difference between using a polling file inbound-endpoint and a Quartz inbound-endpoint polling a file endpoint: the former uses a message receiver, while the latter uses a message requester. Being two different beasts, they have the potential to be implemented quite differently.
然后,您猜怎么着?文件就是这种情况.文件消息接收器使用锁定机制可防止轮询正在处理的文件,而请求者没有.
And, guess what?, that's exactly the case for files. The file message receiver uses a lock mechanism to prevent polling a file that is being processed, while the requester does not.
有趣的一点是请求者的源代码中的以下注释:
The fun bit is this comment in the source code of the requester:
// Don't we need to try to obtain a file lock as we do with receiver
这种疑问以及请求者中缺乏锁使用情况的原因在于,它的行为与接收者不同.永远无法解决的事实可能意味着在该处添加锁会产生不希望的副作用.
This doubt and the lack of lock usage in the requester is what makes it behave differently than the receiver. The fact this has never been solved for sure probably means that adding a lock there has undesired side-effects.
无论如何,如果您坚持使用Quartz,建议您将正在处理的文件移动到另一个目录,以防止重新轮询.文件端点应该可以为您完成这项工作.
In any case, if you persist in using Quartz, I suggest you move the file being processed to another directory to prevent having it re-polled. The file endpoint should be able to do the move for you.
这篇关于Quartz作业读取通配符文件名仅拾取一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!