繁体   English   中英

Linux 上的 Apache Camel 文件 IO

[英]Apache Camel File IO on linux

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

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

尝试删除context.stop(); 从你班上。

启动后,您立即关闭了骆驼。 因此,文件使用者几乎没有机会扫描目录并处理文件。

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

使用 spring-boot 将其作为 Web 应用程序运行或保持主线程阻塞,以便 Camel 保持以下设置

骆驼:springboot:主运行控制器:'真'

暂无
暂无

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

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