STUDIO Visual Editor
-
Add a For Each scope in your flow at the point where you want to initiate the For Each scope processing.
-
Insert one or more message processors inside the For Each scope area to define how Mule should process each element within the message collection. The For Each scope can contain any number of message processors as well as references to child flows.
The only type of message processor you cannot drag into a For Each scope is an inbound connector.
If you drag a two-way connector into a For Each scope, Mule automatically converts it to an outbound-only connector.
Field Default Value Description XML Display Name
For Each
Customize to display a unique name for the scope in your application.
doc:name="For Each"
Collection
(Optional) Enter an expression that tells For Each where to find the data it must split and process. For example, enter an expression that instructs For Each to split and process a collection from the header section – rather than the payload. Unless this field specifies otherwise, For Each assumes that the message payload is the collection.
collection="#[payload.topic]"
Counter Variable Name
counter
(Optional) Enter a name in this field to label the variable that For Each uses to record the number of the elements it has processed. If your collection already uses the label
counter
for another variable, this field will be blank and you will need to enter a different label for the Counter Variable Name, such asindex
.counterVariableName="counter"
Batch Size
1
(Optional) Enter an integer to indicate the number of elements in each batch that For Each processes. Potentially, these batches promote quicker processing. If greater than one, each batch is treated as a separate Mule message. For example, if a collection has 200 elements and you set the batch size to 50, For Each will iteratively process 4 batches of 50 elements, each as a separate Mule message.
batchSize="50"
Root Message Variable Name
rootMessage
(Optional) Enter a name in this field to label the variable that For Each uses to reference the complete, unsplit message collection. If your collection already uses the label
rootMessage
for another variable, this field will be blank and you will need to enter a different label for the Root Message Variable Name.rootMessageVariableName="rootMessage"
XML Editor or Standalone
-
Add a For Each element to your flow at the point where you want to initiate a For Each processing block. Refer to the code sample below.
Element Description For Each
Use to create a block of message processors that iteratively process elements within a collection.
-
Configure the scope according to the table below.
Element Attribute Default Value Description doc:name
For Each
Customize to display a unique name for the async scope in your application.
Note: Attribute not required in Mule Standalone configuration.
collection
Payload
(Optional) Enter an expression that tells For Each where to find the data it must split and process. For example, enter an expression that instructs For Each to split and process a collection from the header section – rather than the payload. Unless this attribute specifies otherwise, For Each assumes that the message payload is the collection.
counterVariableName
counter
(Optional) Specify to label the variable that For Each uses to record the number of the elements it has processed. If your collection already uses the label
counter
for another variable, you will need to select a unique name.batchSize
1
(Optional) Specify an integer to indicate the number of elements in each batch that For Each processes. Potentially, these batches promote quicker processing. For example, if a collection has 200 elements and you set the batch size to 50, For Each will iteratively process 4 batches of 50 elements.
rootMessageVariableName
rootMessage
(Optional) Specify to label the variable that For Each uses to reference the complete, unsplit message collection. If your collection already uses the label
rootMessage
for another variable, you will need to select a unique name. -
Add nested elements beneath your
foreach
element to define how Mule should process each element within the message collection. The For Each scope can contain any number of message processors as well as references to child flows.<foreach collection="#[payload.name]" doc:name="For Each" counterVariableName="counter" rootMessageVariableName="rootMessage" batchSize="5"> <some-nested-element/> <some-other-nested-element/> </foreach>