How to schedule a service using Quartz component that will invoke a file uploader on a periodic basis?

StackOverflow https://stackoverflow.com/questions/14478401

  •  17-01-2022
  •  | 
  •  

Question

This is an extension of my previous question How to upload multiple files via REST over HTTP using Mule?. The requirement say that, on every Wednesday at 10AM the files has to be uploaded. Henceforth I need a scheduler for accomplishing this. And I found that the solution is "Quartz" inbound component with Cron Expression.

But how can I do so? Because I cannot have two "inbound-endpoint".(quartz and file) e.g.

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

If I run I get error

Exception in thread "main" org.mule.module.launcher.DeploymentInitException: SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'file:inbound-endpoint'.

So what is the change that I need to do?

Please help

Était-ce utile?

La solution

Try this

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

Autres conseils

You have two options:

a. Replace the file inbound endpoint with a component that handles the File processing. It will be triggered by Quartz, pick up the file(s) from the folder and pass it to the outbound endpoint.

b. Don't use the Quartz endpoint and override org.mule.transport.file.FileMessageReceiver to implement your custom scheduling for polling files.

The first alternative is the easier one.

The following just a work round if you couldn't find the exact what you need.

1- You could have 2 flows instead of one, one to do the normal job with normal inbound and one for quartz:inbound-endpoint.

2- You could make your scheduler to put messages on a queue and have an other flow to pick up messages from that queue and process.

3- You could have a component with quartz:inbound-endpoint as suggested here http://blogs.mulesoft.org/using-quartz-to-trigger-a-service/

Hope one of the above helps.

Sorry couldn't put this as a comment as it is too long so here it is an example for <quartz:endpoint-polling-job> from Mule website:

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

Hope the above helps

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top