使用以下代码创建camel路由,但是在源中创建文件时,测试中不会出现任何影响。为什么呢?
public class DriverMain {
public static void main(String[] a) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file://source").to("file://test");
}
});
context.start();
String path = System.getProperty("user.dir")+"\\source";
File dir = new File(path);
File file = new File(path+"\\testfile.txt");
file.createNewFile();
}
}
答案 0 :(得分:0)
Camel定期轮询文件。您正在创建一个文件,但随后立即结束应用程序,而不是留下任何时间让Camel轮询您的文件。默认情况下,Camel在开始轮询之前等待1000毫秒。您可以看到file2 component here的选项。
在此测试中,您需要在创建文件后添加Thread.sleep(2000)
。或者更好的是,将camel作为独立进程运行,并在测试结束时将其杀死。您可以使用org.apache.camel.main.Main
类来完成此操作。有运行Camel standalone here的例子。