java - 从Camel文件组件开始

标签 java apache-camel

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

相关文章:

java - 使用记录器创建文件

java - Apache Camel 中的窃听和多播有什么区别

csv - Apache Camel 在聚合大型(100 万条记录)CSV 文件时出现问题

java - 如何使用多个线程处理大型文本文件中的内容?

java - 二叉搜索树差异键之和

java - 返回事物或导致调用范围/上下文返回的辅助方法

java mongodb - 获取数组长度而不下载所有数据

java - 在 Apache Camel Spring DSL 中使用 ZipSplitter

java - Apache Camel 2.12 : Adding bean to already existing context

java - Camel Wire Tap - 用于接受两个输入