[ 
https://issues.apache.org/jira/browse/CAMEL-15017?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-15017.
---------------------------------
    Fix Version/s: 3.3.0
         Assignee: Claus Ibsen
       Resolution: Fixed

> Can't use custom scheduler in polling consumer
> ----------------------------------------------
>
>                 Key: CAMEL-15017
>                 URL: https://issues.apache.org/jira/browse/CAMEL-15017
>             Project: Camel
>          Issue Type: Bug
>          Components: came-core
>    Affects Versions: 2.25.1
>            Reporter: Lorenzo Benvenuti
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 3.3.0
>
>
> 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
> {code:java}
> from("jpa://myEntity?scheduler=quartz2&scheduler.cron=0+*+*+?+*+*+*")
>    /* ... */
> {code}
> I receive the following error:
> {code:java}
> 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]
> {code}
> 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:
> {code:java}
> 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;
>     }
> }
> {code}
> Thanks,
> lorenzo



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to