Question

I am using looping in my code. I am aware that the loop breaks on the occurrence of first to as stated in Apache Camel: Route loop is lost when choice is added to the path

Now, I have a route definition in which I want to have the routing across different channels before the loop ends. For example :

.loop(simple("${header." + FILE_COUNT + "}"))
    .to("direct:file-iterator")
.end()

from("direct:file-iterator").id("file-iterator")
                                    .to("direct:read-file-checksum")    
                                    .to("direct:file-unzip")

Is there any workaround for this kind of scenario as in my code only the first to gets executed after first iteration?

Was it helpful?

Solution

This route:

public void configure() {
   from("direct:start")
       .loop(2)
       .log("CamelLoopIndex = ${header.CamelLoopIndex}")
       .to("direct:file-iterator")
       .end();

   from("direct:file-iterator")
       .id("file-iterator")
       .log("  in file-iterator")
       .to("direct:read-file-checksum")
       .to("direct:file-unzip");

    from("direct:read-file-checksum")
       .log("    in read-file-checksum");

    from("direct:file-unzip")
       .log("    in direct:file-unzip");
    }
}

Leads to following output:

[main] route1                         INFO  CamelLoopIndex = 0
[main] file-iterator                  INFO    in file-iterator
[main] route2                         INFO      in read-file-checksum
[main] route3                         INFO      in direct:file-unzip
[main] route1                         INFO  CamelLoopIndex = 1
[main] file-iterator                  INFO    in file-iterator
[main] route2                         INFO      in read-file-checksum
[main] route3                         INFO      in direct:file-unzip

This is what I would expect. If this route corresponds to your setup, then your problem is not a loop problem and you should have look into the direct:file-unzip route.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top