Loop - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

The Loop allows for processing a message a number of times, possibly in a different way for each iteration. Useful mostly during testing. Options:

Name

Default Value

Description

copyfalseWhether or not copy mode is used. If false then the same Exchange will be used for each iteration. So the result from the previous iteration will be visible for the next iteration. Instead you can enable copy mode, and then each iteration restarts with a fresh copy of the input Exchange.

For each iteration two properties are set on the Exchange. These properties can be used by processors down the pipeline to process the Message in different ways.

Property

Description

CamelLoopSize

Total number of loops

CamelLoopIndex

Index of the current iteration (0 based)

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

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

from("direct:a").loop(8).to("mock:result");

Use expression to determine loop count

from("direct:b").loop(header("loop")).to("mock:result");

Use expression to determine loop count

from("direct:c").loop().xpath("/hello/@times").to("mock:result");

Using the Spring XML Extensions

Pass loop count as an argument

<route>
   <from uri="direct:a"/>
   <loop>
      <constant>8</constant>
      <to uri="mock:result"/>
   </loop>
</route>

Use expression to determine loop count

<route>
   <from uri="direct:b"/>
   <loop>
      <header>loop</header>
      <to uri="mock:result"/>
   </loop>
</route>

See the Camel Website for further examples of this pattern in use.