How do I schedule a service using the Quartz component to run the file loader periodically?

This is an extension of my previous question How do I upload multiple files over REST over HTTP using Mule? ... The requirement says that files must be uploaded every Wednesday at 10 am. From now on I need a scheduler for this. And I found that the solution is an inbound Quartz with Cron Expression.

But how can I do this? Because I cannot have two inbound endpoints. (Quartz and file) for example.

<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 got the error

Exception on stream "main" org.mule.module.launcher.DeploymentInitException: SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting at file element: inbound-endpoint.

So what is the change I need to make?

Please, help

+3


source to share


4 answers


try it



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

      

+4


source


You have two options:

and. Replace the endpoint of the incoming file with a component that handles file handling. It will be initiated by Quartz, pick up the file from the folder and transfer 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 option is simpler.

+1


source


Next working round if you couldn't find what you need.

1- You can have 2 streams instead of one, one for normal operation with normal inbound and one for quartz: inbound-endpoint.

2. You can force the scheduler to queue messages and have another thread to collect messages from that queue and process.

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

Hope one of the above helps.

0


source


Sorry, this cannot be a comment as it is too long, so here is an example for <quartz:endpoint-polling-job>

on the 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 this helps

0


source







All Articles