我几乎没有开始使用Camel,我正在尝试使用文件组件。我想以递归方式处理目录中的每个文件。我试图从(“文件:”)链接到处理器,我不明白为什么它不起作用。在跟踪中,我可以看到驼峰上下文启动了路径。
public static void main(String[] args) throws Exception {
System.out.println("Starting camel");
final CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(
"file://Users/abc123/Documents?recursive=true&noop=true&idempotent=true")
.process(new Processor() {
public void process(Exchange exchange)
throws Exception {
System.out.println("exchange=" + exchange);
}
});
}
});
camelContext.setTracing(true);
camelContext.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
camelContext.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
Thread.currentThread().join();
}
这是日志跟踪:
Starting camel
2015-06-03 00:00:59 INFO DefaultCamelContext - Apache Camel 2.15.2 (CamelContext: camel-1) is starting
2015-06-03 00:00:59 INFO DefaultCamelContext - Tracing is enabled on CamelContext: camel-1
2015-06-03 00:00:59 INFO ManagedManagementStrategy - JMX is enabled
2015-06-03 00:00:59 INFO DefaultTypeConverter - Loaded 182 type converters
2015-06-03 00:00:59 INFO DefaultCamelContext - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
2015-06-03 00:00:59 INFO DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2015-06-03 00:00:59 INFO FileEndpoint - Using default memory based idempotent repository with cache max size: 1000
2015-06-03 00:00:59 INFO DefaultCamelContext - Route: route1 started and consuming from: Endpoint[file://Users/abc123/Documents?idempotent=true&noop=true&recursive=true]
2015-06-03 00:00:59 INFO DefaultCamelContext - Total 1 routes, of which 1 is started.
2015-06-03 00:00:59 INFO DefaultCamelContext - Apache Camel 2.15.2 (CamelContext: camel-1) started in 0.422 seconds
答案 0 :(得分:1)
请务必指定文件夹的正确路径。最好的方法是指定绝对路径:
"file:/Users/abc123/Documents?recursive=true&noop=true&idempotent=true"
您可以使用相对路径,但请确保它确实是应用程序当前工作目录的相对路径。