Java 从Camel文件组件开始

Java 从Camel文件组件开始,java,apache-camel,Java,Apache Camel,我刚刚开始使用Camel,我正在试用文件组件。我想递归地处理目录中的每个文件。我试图从(“文件:”)链接到处理器,但我不明白为什么它不工作。在跟踪中,我可以看到驼峰上下文启动了路由 public static void main(String[] args) throws Exception { System.out.println("Starting camel"); final CamelContext camelContext = new DefaultCamelConte

我刚刚开始使用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"

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

试试绝对文件路径。也许这只是一个不同的相对路径。@DraganBozanovic,我使用的是绝对路径。
//Users/abc123/Documents
Users/abc123/Documents
都不是绝对路径。是的,你是对的。我用一个斜杠(/)替换了双斜杠(/),它开始工作了。是的,我刚才在下面的答案中建议这样做。