For each is used to perform similar set of activities on same payload of a collection. For each will expect collection as input payload and it will iterate over the collection. Point to remember. If it’s a Java collection then it will split the payload by default.
The Foreach scope splits a collection into elements and processes them iteratively through the processors embedded in the scope, then returns the original message to the flow. The collection can be any supported content type, such as application/json
, application/java
, or application/xml
.
General considerations about the For Each scope:
payload.
sale:The For Each scope stores each item of the collection in payload
during each iteration.
You can also split an array into batches to enable quicker processing. Each batch is treated as a separate Mule message. For example, if a collection has 200 elements and you set Batch Size to 50
, the For Each scope iteratively processes 4 batches of 50 elements, each as a separate Mule message.
The Parallel For Each scope enables you to process a collection of messages by splitting the collection into parts that are simultaneously processed in separate routes within the scope of any limitation configured for concurrent-processing. After all messages are processed, the results are aggregated following the same order they were in before the split, and then the flow continues.
Like for-each scope, parallel for each scope also splits the collection of messages into elements.
But, unlike the for-each scope, it processes each element simultaneously in separate routes and the result is the collection of all messages aggregated in the same sequence they were before the split.
The Parallel For Each scope can be configured through the following fields:
Child element | Description |
---|---|
Collection (collection ) | Specifies the expression that defines the collection of parts to be processed in parallel. By default, it uses the incoming payload. |
Attribute | Description |
---|---|
Collection Expression (collection ) | An expression that returns a collection. By default, the payload is taken as the collection to split. |
Timeout (timeout ) | Specifies the timeout in milliseconds for each parallel route. By default, there is no timeout. |
Max Concurrency (maxConcurrency ) | Specifies the maximum level of parallelism for the router to use. By default, all routes run in parallel. |
Target Variable (target ) | Specifies a variable to use for storing the processed payload. By default, the output is saved in the flow’s payload. |
Target Value (targetValue ) | Specifies an expression to evaluate against the operation’s output value. The outcome of this expression is stored in the target variable. By default, this is the same as the operation’s output value. |
Both For Each and Parallel For Each split the defined collection, and the components within the scope process each element in the collection. Also, in both cases, each route runs with the same initial context. The difference between these two scopes are:
MULE:COMPOSITE_ROUTE
error type.If you like my post please follow me to read my latest post on programming and technology.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…