这是我之前的问题如何使用 Mule 通过 REST over HTTP 上传多个文件?。要求每周三上午 10 点必须上传文件。从今以后,我需要一个调度程序来完成此任务。我发现解决方案是带有 Cron 表达式的“Quartz”入站组件。
但是我该怎么做呢?因为我不能有两个“入站端点”。(石英和文件)例如
<flow name="fileUploader" doc:name="fileUploader">
<quartz:inbound-endpoint
jobName="myServiceJob"
repeatInterval="5000"
cronExpression="0 0 10 ? * WED
doc:name="Quartz">
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<file:inbound-endpoint
path="C:\input"
pollingFrequency="5000" moveToDirectory="C:\movehere" doc:name="File"
responseTimeout="10000"/>
<object-to-byte-array-transformer doc:name="Object to Byte Array"/>
<file:outbound-endpoint
path="C:\outputfile"
responseTimeout="10000"
doc:name="File"/>
</flow>
如果我运行我会收到错误
线程“main”org.mule.module.launcher.DeploymentInitException中出现异常:SAXParseException:cvc-complex-type.2.4.a:从元素“file:inbound-endpoint”开始发现无效内容。
那么我需要做什么改变?
试试这个
<file:endpoint name="fileConnector" path="C:\input" pollingFrequency="5000" doc:name="File"/>
<flow name="fileUploader" doc:name="fileUploader">
<quartz:inbound-endpoint
jobName="myServiceJob"
repeatInterval="5000"
cronExpression="0 0 10 ? * WED"
doc:name="Quartz">
<quartz:endpoint-polling-job>
<quartz:job-endpoint ref="fileConnector"/>
</quartz:endpoint-polling-job>
</quartz:inbound-endpoint>
<file:outbound-endpoint
path="C:\outputfile"
responseTimeout="10000"
outputPattern="#[message.inboundProperties.originalFilename]"
doc:name="File"/>
</flow>
您有两个选择:
a.将文件入站端点替换为处理文件处理的组件。它将由 Quartz 触发,从文件夹中提取文件并将其传递到出站端点。
b.不要使用 Quartz 端点并覆盖 org.mule.transport.file.FileMessageReceiver 来实现轮询文件的自定义调度。
第一种选择更简单。
如果您找不到您需要的确切内容,以下只是一个解决方案。
1- 您可以有 2 个流,而不是 1 个,一个用于执行正常入站的正常工作,另一个用于quartz:inbound-endpoint。
2-您可以让调度程序将消息放入队列中,并让其他流程从该队列中获取消息并进行处理。
3-您可以按照此处的建议使用quartz:inbound-endpoint 的组件http://blogs.mulesoft.org/using-quartz-to-trigger-a-service/
希望以上其中一项有帮助。
抱歉无法将其作为评论,因为它太长了,所以这里是来自 Mule 网站的
<quartz:endpoint-polling-job>
的示例:
<service name="testService5">
<description>
The endpoint polling Job will try and perform a 'request' on any Mule endpoint. If a result is received it will be handed off to this 'testService5' service for processing. The trigger will fire every 5 minutes starting at 2pm and ending at 2:55pm, every day. during this period the job will check the file directory /N/drop-data/in every 5 minutes to see if any event data is available. The request will timeout after 4 seconds if there are no files in the directory.
</description>
<inbound>
<quartz:inbound-endpoint name="qEP5" cronExpression="0 0/5 14 * * ?" jobName="job5"
connector-ref="quartzConnector1">
<quartz:endpoint-polling-job>
<quartz:job-endpoint address="file:///N/drop-data/in" timeout="4000"/>
</quartz:endpoint-polling-job>
</quartz:inbound-endpoint>
</inbound>
</service>
希望以上有帮助