You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Lorenzo Benvenuti (Jira)" <ji...@apache.org> on 2020/05/06 13:13:00 UTC

[jira] [Comment Edited] (CAMEL-15017) Can't use custom scheduler in polling consumer

    [ https://issues.apache.org/jira/browse/CAMEL-15017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17100786#comment-17100786 ] 

Lorenzo Benvenuti edited comment on CAMEL-15017 at 5/6/20, 1:12 PM:
--------------------------------------------------------------------

{code}
2020-05-06T14:31:33.964+0200  INFO 17321 --- [  restartedMain] o.a.camel.component.jpa.JpaComponent     : Using EntityManagerFactory found in registry with id [entityManagerFactory] org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@13645b9b
{code}

But I see the {{JpaComponent#doStart}} method, which loads the {{entityManagerFactory}} from the context in case it's null, is called after the {{JpaComponent#createEndpoint}} method; so when the {{JpaEndpoint}} constructor is invoked {{component.getEntityManagerFactory()}} returns null.


was (Author: lbenvenu):
{code}
2020-05-06T14:31:33.964+0200  INFO 17321 --- [  restartedMain] o.a.camel.component.jpa.JpaComponent     : Using EntityManagerFactory found in registry with id [entityManagerFactory] org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@13645b9b
{code}

But I see the {{JpaComponent#doStart}} method, which loads the {{entityManagerFactory}} from the context in case it's null, is called after the {{JpaComponent#createEndpoint}} method; so when the {{JpaEndpoint}} constructor is invoked {{component.getEntityManagerFactory()}} return null.

> 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
>            Priority: Minor
>
> 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)