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.
For each iteration two properties are set on the Exchange
that could be used by processors down the pipeline to process the Message in different ways.
Property |
Description |
---|---|
|
Total number of iterations to be run |
|
Index of the current iteration (0 based) |
that could be used by processors down the pipeline to process the Message in different ways.
Examples
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.
Using the Fluent Builders
Pass loop count as an argument
Use expression to determine loop count
Use expression to determine loop count
Using the Spring XML Extensions
Pass loop count as an argument
Use expression to determine loop count
For further examples of this pattern in use you could look at one of the junit test case
Using This Pattern
If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.