The loop pattern enables you to process a message multiple times. It is used mainly for testing.
On each loop iteration, two exchange properties are set, which can optionally be read by any processors included in the loop.
| Property | Description |
|---|---|
CamelLoopSize
|
Total number of loops |
CamelLoopIndex
|
Index of the current iteration (0 based) |
The following examples show how to take a request from the direct:x endpoint
and then send the message repeatedly to mock:result. The number of loop
iterations is specified either as an argument to loop or by evaluating an
expression at run time, where the expression must evaluate to an
int (or else a RuntimeCamelException is
thrown).
Example 16.2 passes the loop count as a constant:
Example 16.2. Looping based on a constant
<route> <from uri="direct:a"/> <loop> <constant>8</constant> <to uri="mock:result"/> </loop> </route>
Example 16.3 evaluates a simple expression to determine the loop count:
Example 16.3. Looping based on an expression
<route> <from uri="direct:b"/> <loop> <header>loop</header> <to uri="mock:result"/> </loop> </route>








