Linux上的Apache Camel文件IO

gjmwrych  于 2022-11-07  发布在  Apache
关注(0)|答案(2)|浏览(179)

我一直在尝试使用ApacheCamel设置一个简单的程序来读取一个文件并写入一个单独的文件,在Google上搜索了如何并阅读了文档之后,我得到了以下结果

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/...额外的/是从哪里来的,因为我没有在文件路径中有他们?

jgwigjjp

jgwigjjp1#

请尝试从类中删除context.stop();
在启动Camel后立即将其关闭。因此,文件消费者几乎没有机会扫描目录和处理文件。
对着斜线:file://是一个文件URL的开头,就像http://一样。你的文件路径也以/开头,因为它是绝对的。所以你有三个斜杠。

l0oc07j2

l0oc07j22#

使用spring-boot将其作为web应用程序运行,或者保持主线程阻塞,以便Camel保持以下设置
Camel :Spring Boot:主运行控制器:'真'

相关问题