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.

Upvotes: 0

Views: 2406

Answers (2)

vikingsteve
vikingsteve

Reputation: 40408

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.

Upvotes: 3

Ralf
Ralf

Reputation: 6853

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>

Upvotes: 1

Related Questions