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

10,206

Solution 1

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>

Solution 2

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.

Share:
10,206
priyanka.sarkar
Author by

priyanka.sarkar

Student

Updated on June 30, 2022

Comments

  • priyanka.sarkar
    priyanka.sarkar almost 2 years

    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

  • priyanka.sarkar
    priyanka.sarkar over 11 years
    Could you please provide the configuration for point #a and #b?
  • justMe
    justMe over 11 years
    what I meant is to separate what you already have into two flows with one flow for each inbound you have and the same outbound for both. if that is not some ting you want to do search for <quartz:endpoint-polling-job> see if that helps
  • priyanka.sarkar
    priyanka.sarkar over 11 years
    Hi, could you please verify if the flow I put in the edit section is the one u r talking about
  • justMe
    justMe over 11 years
    yes that is something that i thought it will work, I have added an example for <quartz:endpoint-polling-job> as an answer as it was too long for comment.
  • priyanka.sarkar
    priyanka.sarkar over 11 years
    could you please tell about the connector-ref...what is the connector?
  • justMe
    justMe over 11 years
    It is in the documentations here mulesoft.org/documentation/display/MULE3USER/… not sure if you have an account with mule.