简体   繁体   中英

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. 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?

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. If you only want to call the timer one time, you can set repeatCount=1 : http://camel.apache.org/timer

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM