使用骡子 3.7。如果我的目录中有 5 个扩展名为 .csv 的文件,则以下代码仅选取这五个文件之一。如果我删除石英触发器并将其设为普通文件:inbound-endpoint,它将拾取所有五个文件。看起来很简单,但并没有按预期工作。
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>
这是触发两次后的日志:
信息 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 入站端点轮询文件端点之间有一个主要区别:前者使用消息接收者,而后者使用消息请求者。作为两种不同的野兽,它们的实施方式可能会截然不同。
而且,你猜怎么着?文件正是如此。文件消息接收者使用锁定机制 https://github.com/mulesoft/mule/blob/mule-3.x/transports/file/src/main/java/org/mule/transport/file/FileMessageReceiver.java#L210以防止轮询正在处理的文件,而请求者不 https://github.com/mulesoft/mule/blob/mule-3.x/transports/file/src/main/java/org/mule/transport/file/FileMessageRequester.java#L128.
有趣的是请求者源代码中的这条注释:
// Don't we need to try to obtain a file lock as we do with receiver
这种怀疑以及请求者缺乏锁的使用导致其行为与接收者不同。事实上,这个问题从未得到解决,这可能意味着在那里添加锁会产生不良的副作用。
无论如何,如果您坚持使用 Quartz,我建议您将正在处理的文件移至另一个目录,以防止重新轮询。文件端点应该能够为您进行移动。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)