Apache Camel + Quartz Hello World Example | JavaInUse

Apache Camel + Spring + Quartz Hello World Example

In this post we will schedule a camel route to start using Quartz. In previous Apache Camel Java DSL + Spring Example we had written Spring configuration to call a Java DSL route to transfer from one folder to another.
We will now configure to trigger the route after a certain period using quartz.

Apache Camel - Table of Contents

File Transfer Using Java DSL Apache Camel Apache Camel Java DSL + Spring Integration Hello World Example Apache Camel Exception Handling Using Simple Example Apache Camel Redelivery policy using example Integrate Apache Camel and ActiveMQ EIP patterns using Apache Camel Apache Camel Tutorial- Integrate Spring Boot+ Apache Camel Apache Camel Tutorial- Integrate with MySQL DB using SQL query Apache Camel EIP - Splitter and Aggregator pattern Apache Camel Unit Testing Apache Camel + Spring + Quartz Hello World Example Camel application deployment on JBoss Fuse Apache Camel + JAX-RS REST Webservice Apache Camel + CXFRS REST Webservice Apache Camel Routing Slip EIP Pattern Apache Camel Dynamic Router Pattern Apache Camel Load Balancer EIP Pattern Apache Camel Interceptors Apache Camel + Kafka Hello World Example Apache Camel - Marshalling/Unmarshalling XML/JSON Data Example

Lets Begin

The project structure we would be creating will be as follows-

The pom.xml will be as follows-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">






Create the camel processor as follows-
package com.javainuse.processor;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class MyProcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        System.out.println("Executing camel processor");


Create the SimpleRouteBuilder class that extends RouteBuilder and configures the camel route. Here we will also define the quartz configuration using CronScheduledRoutePolicy
package com.javainuse.route;

import org.apache.camel.builder.RouteBuilder;
import com.javainuse.processor.MyProcessor;

public class SimpleRouteBuilder extends RouteBuilder {

    public void configure() throws Exception {
     CronScheduledRoutePolicy startPolicy = new CronScheduledRoutePolicy();
		startPolicy.setRouteStartTime("0 0/3 * * * ?");

	from("file:C:/inputFolder?noop=true").routePolicy(startPolicy).noAutoStartup().process(new MyProcessor())


Create the application context that calls the Java DSL RouteBuilder class using the routeBuilder
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"

	<bean id="routeBuilder" class="com.javainuse.route.SimpleRouteBuilder" />

	<camelContext xmlns="http://camel.apache.org/schema/spring">
		<routeBuilder ref="routeBuilder" />

Finally load the context file to start the Java DSL camel route.
package com.javainuse.main;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-camel.xml");
        System.out.println("Application context started");
        try {
            Thread.sleep(5 * 60 * 1000);
        catch (InterruptedException e) {

The files will be copied from inputfolder to the outputfolder after delay of 3 minutes we have configured using quartz.

Download Source Code

Download it - Apache Camel + Spring + Quartz Integration simple example

See Also

Spring Boot Hello World Application- Create simple controller and jsp view using Maven Spring Boot Tutorial-Spring Data JPA Spring Boot + Simple Security Configuration Pagination using Spring Boot Simple Example Spring Boot + ActiveMQ Hello world Example Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot Main Menu Spring Boot Interview Questions