Search code examples
quartz-schedulerapache-camel

Problem in using Apache camel with Quartz SCheduler


I am new to Apache camel and quartz scheduler. I am trying to to use them both in integration but unable to do it. I found a little article in "Camel in Action" book but I didn't manage to run the program also- here is my code

package com.cockpitconfig.schedulars;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class TestScheduler {

    public static void main(String args[]) throws Exception {
        CamelContext context = new DefaultCamelContext();
        context.disableJMX();
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() {
                from(
                        "quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
                        .setBody().simple("Current time is ").to("stream:out");
            }
        });

        context.start();
        Thread.sleep(10000);

        context.stop();
    }
}

But it is giving error

Exception in thread "main" java.lang.InstantiationError: org.quartz.SimpleTrigger
    at org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:119)
    at org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:54)
    at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75)
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:419)
    at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:47)
    at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:189)
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:110)
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)
    at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:73)
    at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:88)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:751)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:174)
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:610)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1514)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1306)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1213)
    at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:65)
    at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:52)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1191)
    at com.cockpitconfig.schedulars.TestScheduler.main(TestScheduler.java:24)

Does anybody have solution to this problem?


Solution

  • what version of Camel are you using? it worked fine for me using 2.8-SNAPSHOT. just make sure you have camel-core, camel-quartz and camel-stream dependencies in your path.