Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-15017

Can't use custom scheduler in polling consumer

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.25.1
    • 3.3.0
    • came-core
    • None
    • Unknown

    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

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            lbenvenu Lorenzo Benvenuti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: