简体   繁体   English

如何从http使用apache camel只读一次csv文件?

[英]How can I read csv file using apache camel only once from http?

I try to create a route, that can access http url with csv file and simply print the content of it. 我尝试创建一个路径,可以使用csv文件访问http url并简单地打印它的内容。 Unfortunately the file is being read continuously. 不幸的是,文件正在不断读取。

  1. Is it possible to do read it only once and then stop processing? 是否可以只读一次然后停止处理?
  2. Why does "direct:start" not work in this example and I have to use timer? 为什么“direct:start”在这个例子中不起作用而我必须使用计时器?

Here is my code: 这是我的代码:

context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("timer://start?delay=5000")
                        .to("http4://127.0.0.1:18080/data.csv")
                        .unmarshal().csv()
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                String list = exchange.getIn().getBody(String.class);
                                log.info(list);
                  //Here I would like to stop the route when file reading is finished
                            }
                        });
        });

Thanks! 谢谢!

The timer will keep calling every 5th seconds. 计时器将每隔5秒钟保持一次通话。 If you only want to call the timer one time, you can set repeatCount=1 : http://camel.apache.org/timer 如果您只想调用一次计时器,可以设置repeatCount=1httprepeatCount=1

But you may need to consider do you want to only let it run once. 但您可能需要考虑是否只让它运行一次。 What if you need to call that HTTP url again sometime later? 如果您需要稍后再次调用该HTTP URL,该怎么办?

And also as Frank commented there is a way to stop a route from a route: http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html 而且正如弗兰克评论的那样,有一种方法可以阻止路线的路线: http//camel.apache.org/how-can-i-stop-a-route-from-a-route.html

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

相关问题 我如何使用apache-camel在一次轮询中从aws s3目录中读取所有文件 - How do i can read all the files from aws s3 directory in a single poll using apache-camel 如何使用骆驼 http 组件将文件上传到运行在 apache tomcat 服务器上的应用程序? - How can I use camel http compponent to upload a file to an application running on apache tomcat server? 使用Apache Camel从EMS队列中读取xml文件 - Read an xml file from EMS queue using Apache Camel 如何使用Apache Camel读取文件,如何使用Spring批处理文件,读取每一行并将其路由回Apache Camel - How to read file using Apache Camel, process the file using Spring batch, read each line and route it back through Apache Camel Apache Camel Batch处理后如何移动文件? - How can I move file after Apache Camel Batch processing? 如何使用 Apache Camel 从 Java class 访问 JMS 队列? - How can I access a JMS queue from a Java class using Apache Camel? 我如何在Apache Camel中使用xpath获取nodeList - How can i get nodeList using xpath in Apache Camel java - 如何在java中使用apache camel从目录中获取特定文件? - How get specific file from directory using apache camel in java? 如何通过Java Apache HttpClient使用http导入/导出csv - How can I import/export csv using http through Java Apache HttpClient 使用Apache Commons CSV从第二行开始读取文件 - Using Apache Commons CSV to read file starting from the second line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM