简体   繁体   English

Linux 上的 Apache Camel 文件 IO

[英]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我一直在尝试设置一个简单的程序来读取文件并使用 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();
}

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.但是我在我的磁盘上的任何地方都没有得到tempOut.txt (至少对我来说是有意义的)。 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?我还注意到,在控制台输出中,它说“ ...consuming from: Endpoint[file:///home/...额外的/来自哪里,因为我在文件路径中没有它们?

Try to remove the context.stop(); 尝试删除context.stop(); from your class. 从你班上。

You immediately shut down Camel after you started it. 启动后,您立即关闭了骆驼。 Therefore the file consumer has only little chance to scan the directory and process the files. 因此,文件使用者几乎没有机会扫描目录并处理文件。

To the slashes: file:// is the beginning of a file URL, just like http:// . 以斜杠表示: file://是文件URL的开头,就像http:// And your file path starts with a / too because it is absolute. 您的文件路径也以/开头,因为它是绝对的。 Therefore you got three slashes. 因此,您得到了三个斜杠。

use spring-boot to run it as web application or keep the main thread blocked so that Camel stays up with below setting使用 spring-boot 将其作为 Web 应用程序运行或保持主线程阻塞,以便 Camel 保持以下设置

camel: springboot: main-run-controller: 'true'骆驼:springboot:主运行控制器:'真'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM