How to Iterate with Apache Camel


Like the animal of the same name, Apache Camel allows programmers to travel great distances in a relatively short period of time. Before Apache Camel, programmers had to hard code their data storage, web framework and business objects. But with the the advent of Apache Camel, you can now route data by specifying rules in your code. To this end, you can use Apache Camel to iterate -- or loop -- through data using either Fluent Builders of Spring XML Extensions. Most likely, you'll only iterate for testing purposes.

  • Open the Java development environment of your choice and find the portion of your code that requires you to iterate with Apache Camel.

  • Iterate through an item a specified number of times (15, in this example) by passing the number of loops to perform as a numerical argument:

    from ("endpoint:x").loop(15)to('mock:result");

    Use the <loop> XML tag to accomplish the same objective from within Spring XML Extentions:


    <from uri="endpoint:x"/>



    &lt;to uri="mock:result"/>



  • Set the number of iterations programmatically by using an expression that reduces to a numerical value:


    Use the <loop> XML tag in combination with the <header> tag to accomplish the same objective from within Spring XML Extentions:


    <from uri="endpoint:y"/>



    &lt;to uri="file:result"/>



  • Save your work and review it to ensure it works as expected.

Related Searches


  • Photo Credit Jupiterimages/ Images
Promoted By Zergnet



Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!