linux上的Apache Camel文件IO



我一直在尝试设置一个简单的程序,使用ApacheCamel读取文件并写入单独的文件,在谷歌上搜索了如何读取并阅读了文档后,我提出了以下

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

启动Camel后,您会立即关闭它。因此,文件使用者扫描目录和处理文件的机会很小。

对于斜杠:file://是文件URL的开头,就像http://一样。您的文件路径也以/开头,因为它是绝对的。所以你有三个斜线。

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

骆驼:弹簧靴:主运行控制器:"true">

最新更新