java - 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?
解决方案
尝试context.stop();
从您的班级中删除。
启动Camel后立即关闭它。因此文件消费者几乎没有机会扫描目录和处理文件。
斜杠:file://
是文件 URL 的开头,就像http://
. 而且您的文件路径也以 a 开头,/
因为它是绝对的。因此,您得到了三个斜线。
推荐阅读
- c - 使用 exec 写入文件
- rcpp - 将对 int-double 写入磁盘上的二进制文件的快速方法
- scala - Spark scala:根据条件将字符串附加到Dataframe的现有列
- pandas - 通过 Pandas Dataframe 中的分隔符将列拆分为未知数量的列
- javascript - 无法清除Interval(),变量显示未定义
- python - 在python中更改数组的内容
- android - 如何在登录屏幕出现时阻止用户返回,而不是终止活动(Firebase 身份验证)
- python - Pytorch“NCCL 错误”:未处理的系统错误,NCCL 版本 2.4.8”
- flutter - 检查 popUntil 是否可能/检查导航堆栈中是否命名路由
- apache-kafka - 为什么从 v0.6.0 升级到 v0.8.1 时 ksqldb-server 崩溃?