Apache Camel – File Copy

Maven Dependencies

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

Camel Router

package com.dineshkrish.example2;

import org.apache.camel.builder.RouteBuilder;

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class FileCopyRouter extends RouteBuilder {

	@Override
	public void configure() throws Exception {
		
		from("file:input_dir?noop=true")
		.to("file:output_dir");
		
		System.out.println("File is moved");
	}

}

Main Program

package com.dineshkrish.example2;

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

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class FileCopyCamel {

	public static void main(String[] args) {
		// creating an instance for camel context
		CamelContext context = new DefaultCamelContext();

		// creating an instance for router
		FileCopyRouter router = new FileCopyRouter();

		try {

			// adding router to context
			context.addRoutes(router);

			// starting the camel context
			context.start();

			// stopping the camel context
			context.stop();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Output

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
File is moved

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.