使用Mule 3.7。如果我在一个扩展名为.csv的目录中有5个文件,则下面的代码只会获取五个文件中的一个。如果我删除石英触发器并使其成为普通文件: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>
这是两次射击后的日志:
INFO 2015-10-05 15:09:30,063 [scheduler-quartzcronfilepickup_Worker-1] org.mule.lifecycle.AbstractLifecycleManager:Initialising:'fileInConnector.requester.2009817243'。对象是:FileMessageRequester
INFO 2015-10-05 15:09:30,069 [scheduler-quartzcronfilepickup_Worker-1] org.mule.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.mule.lifecycle.AbstractLifecycleManager:Initialising:'fileInConnector.requester.636902426'。对象是:FileMessageRequester
INFO 2015-10-05 15:09:45,016 [scheduler-quartzcronfilepickup_Worker-2] org.mule.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
答案 0 :(得分:2)
使用轮询文件入站端点和Quartz入站端点轮询文件端点之间存在重大差异:前者使用消息接收器,而后者使用消息请求者。作为两种不同的野兽,它们有可能以不同的方式实施。
而且,猜猜是什么?这就是文件的情况。文件消息接收器uses a lock mechanism,以防止轮询正在处理的文件,而requester does not。
有趣的一点是请求者的源代码中的这个注释:
// Don't we need to try to obtain a file lock as we do with receiver
这种疑问以及请求者中锁定使用的缺乏使得它的行为与接收者不同。事实上,这一点从来没有得到解决,这可能意味着在那里添加锁具有不良的副作用。
在任何情况下,如果您坚持使用Quartz,我建议您将正在处理的文件移动到另一个目录以防止重新轮询。文件端点应该能够为您完成移动。