Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

3. Loop
The Loop allows to process the a message a number of times and possibly process them in a different way. Useful mostly for testing.

Example

The following example shows how to take a request from the direct:x endpoint , then send the message repetitively to "mock:result". The number of times the message is sent is either passed as an argument to loop(), or determined at runtime by evaluating an expression. The expression must evaluate to an int, otherwise a RuntimeCamelException is thrown.

For each iteration two properties are set on the exchange:

CamelIterationCount

Total number of iterations to be run

CamelIterationIndex

Index of the current iteration (0 based)

that could be used by processors down the pipeline to process the Exchange in different ways.

Using the Fluent Builders

Pass loop count as an argument

...

Wiki Markup
{snippet:id=ex2|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml}

Use expression to determine loop count

Wiki Markup
{snippet:id=ex3|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml}

...