Apache Camel
Apache Camel is a simple routing engine which provides the implementation of Enterprise Integration Pattern using Java or other Domain specific language. See more about Apache Camel and Enterprise Integration Patterns. In this example we are going to create a simple Router to copy files from one directory to another directory upon starting Camel Context.Environment Setup
Create a maven project and add below dependency<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.12.1</version>
</dependency>
Create a Java class to implement Router and start Camel<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.12.1</version>
</dependency>
package com.vinod.test;
import java.io.File;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class CamelSimpleRouteExample {
public static void main(String[] args) {
try {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file://source").to("file://destination");
}
});
context.start();
File ff = new File("source//Temp.txt");
ff.createNewFile();
Thread.sleep(1000);
context.stop();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run it...import java.io.File;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class CamelSimpleRouteExample {
public static void main(String[] args) {
try {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file://source").to("file://destination");
}
});
context.start();
File ff = new File("source//Temp.txt");
ff.createNewFile();
Thread.sleep(1000);
context.stop();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
After running this program we can see the default source and destination directories are created and transferring the Temp.txt in to destination folder.
Download example
https://github.com/kkvinodkumaran/camel
Reference
Apache Camel
No comments:
Post a Comment