Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel: Accessing CamelLoopIndex

Tags:

apache-camel

I have the following route DSL:

from("file:" + autoLoadBaseDir + "?move=.classified")
                .loop(fileTypes.length)
                    .choice()
                        .when(header("CamelFileName").contains(fileTypes[Integer.valueOf("${CamelLoopIndex}")]))
                            .to("file:" + classesBaseDir + "/" + fileTypes[Integer.valueOf("${CamelLoopIndex}")]);

As shown, I wish to access the CamelLoopIndex and use it as an index in an array. The expression is not evaluated, hence the route is not created. What am I doing wrong? Thanks in advance.

Documentation on this is pretty scanty, and I've not been successful getting a solution after hours of searching.

UPDATE: I've posted the same question to the Camel Users Mailing List.

like image 540
okello Avatar asked May 09 '26 21:05

okello


2 Answers

You should use ${property.CamelLoopIndex}

like image 104
katrin Avatar answered May 11 '26 13:05

katrin


you can use a processor or directly access the property

${exchangeProperty.CamelLoopIndex}

...
    .loop(4)
       .log("${exchangeProperty.CamelLoopIndex}")
       .process(exchange -> {
          Integer index = (Integer) exchange.getProperty(Exchange.LOOP_INDEX);
       })
     .end()
...

enter image description here https://camel.apache.org/components/latest/eips/loop-eip.html https://camel.apache.org/manual/latest/processor.html

Hope this helps

like image 43
Marcos Rufino Avatar answered May 11 '26 13:05

Marcos Rufino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!