Description
Hi,
I came across this error while trying to use a Quartz scheduler with a JPA component but I guess it applies to all the endpoints extending ScheduledPollEndpoint.
If I use
from("jpa://myEntity?scheduler=quartz2&scheduler.cron=0+*+*+?+*+*+*") /* ... */
I receive the following error:
org.apache.camel.FailedToCreateConsumerException: Failed to create Consumer for endpoint: jpa://myEntity?scheduler=quartz2&scheduler.cron=0+*+*+%3F+*+*+*. Reason: There are 1 scheduler parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{cron=0 * * ? * * *}] at org.apache.camel.impl.ScheduledPollConsumer.doStart(ScheduledPollConsumer.java:433) ~[camel-core-2.25.1.jar:2.25.1] at org.apache.camel.component.jpa.JpaConsumer.doStart(JpaConsumer.java:530) ~[camel-jpa-2.25.1.jar:2.25.1]
This happens because the scheduler is an instance of DefaultScheduledPollConsumerScheduler. After some debugging I found out that when ScheduledPollEndpoint#configureScheduledPollConsumerProperties is called, schedulerName is always null (Endpoint.configureProperties is invoked before setting endpoint properties using reflection).
The only workaround I've found so far is to write a custom component and force the scheduler on the endpoint:
public class MyJpaComponent extends JpaComponent { @Override protected Endpoint createEndpoint(String uri, String path, Map<String, Object> options) throws Exception { JpaEndpoint endpoint = (JpaEndpoint) super.createEndpoint(uri, path, options); endpoint.setScheduler("quartz2"); return endpoint; } }
Thanks,
lorenzo