I am developing a custom component, endpoint and consumer. It generally works with the default Camel scheduling options: initialDelay and delay.
public class MyEndPoint extends ScheduledPollEndpoint
@Override
public Consumer createConsumer(Processor processor) throws Exception {
return new MyConsumer(this, processor);
}
public class MyConsumer extends ScheduledPollConsumer {
public MyConsumer (ScheduledPollEndpoint endpoint, Processor processor)
{
super(endpoint, processor);
}
@Override
protected int poll() throws Exception {
// do something
}
}
Now, I just wanted to use the Quartz scheduler with my custom component. In the from URI, I added:
&scheduler=quartz&scheduler.cron=0+/2++++?
In the consumer, I can find the settings for the scheduler getting passed. My question is how can I actually run my poll method on the quartz schedule instead of the default Camel schedule. What’s currently happening is that the scheduler is running at the default 500ms and ignoring the Quartz scheduler, although the setting is available and I’ve removed the initialDelay and delay parameters. Am I supposed to override a property or anything?
Thanks to Samar, I double-checked my code to see what could be causing the strange behavior and it turns out that my “MyEndpoint” class mentioned above had errantly contained an override of the createPollingConsumer method. It looked something like this:
public PollingConsumer createPollingConsumer() throws Exception {
return super.createPollingConsumer();
}
Then, I found in the documentation on the Red Hat site that you should not override the createPollingConsumer method while using the ScheduledPollEndpoint class. I thought it might just be doing nothing. So, the custom consumer is working and I verified that the job is getting scheduled per the Quartz cron expression.
Reference:
https://docs.redhat.com/en/documentation/red_hat_fuse/7.5/html/apache_camel_development_guide/endpointintf#Component-Impl-Endpoint-ScheduledPollEndpoint
After item #6, there is a note:
Do not override the createPollingConsumer() method.
0