这是一个很简单的Camel例子,代码如下:
public static void main(String[] args) throws Exception {
//创建Camel上下文
DefaultCamelContext camelContext = new DefaultCamelContext();
//添加一个路由,参数为路由建造者
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
this.from("file:H:/temp/in").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
GenericFile<File> gf = exchange.getIn().getBody(GenericFile.class);
File file = gf.getFile();
PrintStream ps = new PrintStream(System.out);
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = null;
while((line=br.readLine())!=null) {
ps.println(line);
}
ps.close();
br.close();
}
}).to("file:H:/temp/out");
}
});
//启动上下文
camelContext.start();
//防止主线程退出
Object object = new Object();
synchronized (object) {
object.wait();
}
}原文:http://blog.csdn.net/xtayfjpk/article/details/39090269