gpt4 book ai didi

java - 从Camel文件组件开始

转载 作者:行者123 更新时间:2023-11-30 08:09:29 24 4
gpt4 key购买 nike

我刚刚开始使用 Camel,正在尝试文件组件。我想递归地处理目录中的每个文件。我尝试将 from("file:") 链接到处理器,但我不明白为什么它不起作用。在跟踪中,我可以看到 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

最佳答案

请务必指定正确的文件夹路径。最好的方法是指定绝对路径:

"file:/Users/abc123/Documents?recursive=true&noop=true&idempotent=true"

您可以使用相对路径,但请确保它确实是应用程序当前工作目录的相对路径。

关于java - 从Camel文件组件开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com