For Each and Parallel For Each in Mule 4

What is For Each?

  • The Foreach scope splits a collection and process them sequentially

  • It returns the original payload at the end of forEach.

  • If error occurs then it stops processing rest of the records.

Example:

Inside forEach payload is modified but we get only original payload at the end of forEach.

Parallel For Each:

  • The Parallel forEach spilts the collections and process the payload parallely

  • If error occurs inside forEach it continues with rest of the records and combines the error with modified payload

  • It returns the modified payload at the end of parallel forEach.

  • The modified payload will be in Java format it can be converted to JSON.

Example: