欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CamelJmsToFileDemo 博客分类: Apache Camel Camel 

程序员文章站 2024-02-22 14:17:10
...


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileConverter;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ssgx.calypso.processor.CompareProcessor;

public class CamelJmsToFileDemo {

public CamelJmsToFileDemo() {
}

private static int m = 0;
static Logger LOG = LoggerFactory.getLogger(CamelJmsToFileDemo.class);

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
//只处理.txt后缀结尾的文件
from("file://test1?include=.*\\.txt&delay=30000").to("file://test");
from("file://test2?include=.*\\.txt&delay=30000").to("file://test");
}
});
context.start();
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
Thread.sleep(5000);
File file = new File("test");
System.out.println(" path=" + file.getAbsolutePath());

String[] strs = file.list();
InputStream is = new FileInputStream(new File("fileList/fileList.txt"));
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
String temp = null;
boolean all = true;//all file is ready
while ((temp = reader.readLine()) != null) {
System.out.println("neirong:" + temp);
for (int i = 0; i < strs.length; i++) {
System.out.println("strs[i]:" + strs[i]);
if (temp.equals(strs[i])) {
break;
}
if (temp != strs[i] && i == strs.length - 1) {
all = false;
}
}
}
System.out.println("all:" + all);
if (all) {
from("file://test").process(new CompareProcessor());
}
}
});
// context.addRoutes(new TimerRouteBuilder());
Thread.sleep(5000);

context.stop();
}

}
相关标签: Camel