Linux上的Apache Camel文件IO

我一直在尝试建立一个简单的程序来读取文件并使用Apache Camel写入一个单独的文件,并且在仔细研究了如何阅读文档之后,我提出了以下建议


public static void main(String[] argv) {

    CamelContext context = new DefaultCamelContext();

    RouteBuilder route = new RouteBuilder() {

        @Override

        public void configure() throws Exception {

             from("file:/home/user/?fileName=temp.txt&charset=UTF-8&noop=true")

             .to("/home/user/?fileName=tempOut.txt&charset=UTF-8");

        }

    }


    context.addRoutes(route);

    context.start();

    context.stop();

}

控制台输出如下


[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.11.1 (CamelContext: camel-1) is starting

[main] INFO org.apache.camel.management.ManagementStrategyFactory - JMX enabled.

[main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 172 type converters

[main] INFO org.apache.camel.component.file.FileEndpoint - Endpoint is configured with noop=true so forcing endpoint to be idempotent as well

[main] INFO org.apache.camel.component.file.FileEndpoint - Using default memory based idempotent repository with cache max size: 1000

[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: Endpoint[file:///home/justin/?charset=utf-8&fileName=temp1.txt&noop=true]

[main] INFO org.apache.camel.management.DefaultManagementLifecycleStrategy - Load performance statistics enabled.

[main] INFO org.apache.camel.impl.DefaultCamelContext - Total 1 routes, of which 1 is started.

[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.11.1 (CamelContext: camel-1) started in 0.680 seconds

[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.11.1 (CamelContext: camel-1) is shutting down

[main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)


但是tempOut.txt,我在磁盘上的任何位置(至少对我来说这是没有道理的)都没有得到结果。我的问题是为什么呢?我也注意到控制台输出中显示“...consuming from: Endpoint[file:///home/...多余/的来自哪里,因为我在文件路径中没有它们?


阿波罗的战车
浏览 351回答 1
1回答

红颜莎娜

尝试context.stop();从您的班级中删除。启动后,您立即关闭了骆驼。因此,文件使用者几乎没有机会扫描目录并处理文件。斜线:file://是文件URL的开头,就像http://。并且您的文件路径也以a开头,/因为它是绝对的。因此,您得到了三个斜杠。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java