为了账号安全,请及时绑定邮箱和手机立即绑定

Linux上的Apache Camel文件IO

Linux上的Apache Camel文件IO

阿波罗的战车 2021-05-14 18:15:35
我一直在尝试建立一个简单的程序来读取文件并使用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)但是tempOut.txt,我在磁盘上的任何位置(至少对我来说这是没有道理的)都没有得到结果。我的问题是为什么呢?我也注意到控制台输出中显示“...consuming from: Endpoint[file:///home/...多余/的来自哪里,因为我在文件路径中没有它们?
查看完整描述

1 回答

?
红颜莎娜

TA贡献1842条经验 获得超12个赞

尝试context.stop();从您的班级中删除。

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

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


查看完整回答
反对 回复 2021-05-26
  • 1 回答
  • 0 关注
  • 350 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信