↓ Skip to main content

New and noteworthy

·235 words·2 mins
Sergii Zolotarov
Author
Sergii Zolotarov
Twenty years of Java, from Kyiv to Leeuwarden. Currently at Booking.com

Camel 2.4.0 introduced a nice feature which broke Quartz routes in our project:


Introduced StartupListener to allow components/endpoints/producers/consumers etc. as a listener to be notified when CamelContext have just been started. This allows any custom logic to be executed as a late starter. This ensures Quartz scheduler is only started when all the routes and so forth is started and running.

The problem is - if you have no routes in camel context at startup you will never see Quartz working, because QuartzComponent.startScheduler is invoked after all subscriptions were added and the context had been started. The startScheduler checks whether private static Scheduler instance is null and if so exits. The tricky thing is, the scheduler field is populated only when the component is started in the doStart method. But it’s a bit too late. The scheduler is there and there is noone to start it, hence the dead Quartz routes.

I made a simple fix for those who really need to dynamically populate camel routes after the context was started, here it is:


    <camel:camelContext id="camelContext" handleFault="true" streamCache="false" trace="true" autoStartup="true">
      <camel:route>
        <camel:from uri="quartz://dummy/dummytrigger?fireNow=true"/>
        <camel:to uri="mock:something"/>
      </camel:route>
    </camel:camelContext>

This way QuartzComponent gets a functional and started scheduler for all new routes that you add later.

Hope Claus will figure out from this a possible graceful fix :)

Here (not archived) is a project which reproduces the thing.


First published on the old anydoby.com blog on 2010-10-06.