Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 572
priyanka.sarkar Avatar asked Dec 12 '25 14:12

priyanka.sarkar


2 Answers

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>
like image 87
Niladri Biswas Avatar answered Dec 15 '25 13:12

Niladri Biswas


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.

like image 29
Seba Avatar answered Dec 15 '25 13:12

Seba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!