首页 > 解决方案 > Apache Camel File IO on linux

问题描述

I have been trying to set up a simple program to read in a file and write to a separate file using Apache Camel, and after googling how to and reading the documentation, I have come up with the following

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();
}

and the console output is as follows

[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)
[Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: Endpoint[file:///home/justin/?charset=utf-8&fileName=temp1.txt&noop=true]
[main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.11.1 (CamelContext: camel-1) uptime 0.759 seconds
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.11.1 (CamelContext: camel-1) is shutdown in 0.032 seconds

However I get no resulting tempOut.txt anywhere (at least that would make sense to me) on my disk. My question is why is that? also I have noticed that in the console output it says "...consuming from: Endpoint[file:///home/... where are the extra /'s coming from as I do not have them in the file path?

标签: javalinuxapache-camel

解决方案


尝试context.stop();从您的班级中删除。

启动Camel后立即关闭它。因此文件消费者几乎没有机会扫描目录和处理文件。

斜杠:file://是文件 URL 的开头,就像http://. 而且您的文件路径也以 a 开头,/因为它是绝对的。因此,您得到了三个斜线。


推荐阅读