Using a timer with Quartz and Apache Camel

I have a problem with Camel and quartz. I want to run a trigger with Quartz, so I wrote this simple code where I want to print time every two seconds on the console:

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

And I get this exception: Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[quartz://myGroup/myTimerName?cron=0+0+8+... because of Failed to resolve endpoint: quartz://myGroup/myTimerName?cron=0+0+8+*+*+* due to: No component found with scheme: quartz

To begin with, I put a dependency in pom.xml:

  <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-quartz2</artifactId> <version>${camel.version}</version> </dependency> 

where camel.version is 2.15.1

Can someone help me?

+5
source share
1 answer

You import the camel-quartz 2 component into the pom.xml file, trying to use the old quartz component.

Quartz: http://camel.apache.org/quartz.html

Quartz2: http://camel.apache.org/quartz2.html

Try using the following URI for the route:

 quartz2://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1 
+4
source

All Articles