简体   繁体   中英

How to reschedule Apache Camel Quartz (CronScheduledRoutePolicy) endpoint route on failure

This is my schedular(CronScheduledRoutePolicy) for data processing.

    <route>
        <from uri="quartz://schedule?cron=0+1+0+*+*+?+*"/>
        <bean ref="processData" method="scheduleData" />
            <convertBodyTo type="java.util.List" />
            <to uri="activemq:queue:DATA.GENERATEDLIST?mapJmsMessage=false" />

        <onException>
            <exception>java.lang.Exception</exception>
            <to uri="activemq:queue:DATA.ERROR.MESSAGES?mapJmsMessage=false&amp;jmsMessageType=Text" />
        </onException>
    </route>

It runs everyday 12.01 am, the question is if any error occurs how to re-run or re-schedule manually using schedule id or route id.

Thanks.

Ok, since you have clarified your question, you need 2 ways to be able to do your data processing: firstly via the cron schedule and then manually.

I am going to suggest you break it into 3 routes (this is obviously java DSL, but you can easily convert it to xml).

  1. First route is the quartz schedule- it calls the processing route.

     from("quartz://schedule?cron=0+1+0+*+*+?+*") .to("direct:doProcessing") ; 
  2. Second route does the processing

     from("direct:doProcessing") // do awesome stuff here... ; 
  3. Third route is your manual restart

     from("timer://manualRestart?repeatCount=1") .routeId("manualRestart") .noAutoStartup() .to("direct:doProcessing") ; 

Now, you can start the route with id "manualRestart" using the route-start command on the command line, or via a tool like fmc .

Hope this helps.

You could use a re-delivery policy to re-try the exchange N times if an exception is encountered.

<route>
    <!-- ... -->
    <onException>
        <exception>java.lang.Exception</exception>
        <redeliveryPolicy redeliveryDelay="100000" maximumRedeliveries="3"/>
        <to uri="activemq:queue:DATA.ERROR.MESSAGES?mapJmsMessage=false&amp;jmsMessageType=Text" />
    </onException>
</route>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM