Skip to content

Scatter-Gather in Mule 4 – Study Notes

What is Scatter-Gather Router?

The scatter-gather is a router event processor. It can process a mule event through different routes in parallel.

Each route will receive a “copy” (a reference) of the original mule event and processes the event on different routes, on separate threads.

The result of the router will combine the results of each route into a new Mule event. The result will be ready only after the most time-consuming route will be finished.

Scatter-Gather Input

Repeatable stream.

Why? Because non-repeatable streams can be read only once. After that they are lost. The good news is that the default of Mule is that all streams are repeatable unless configured the other way.

Scatter-Gather Output

An object which contains all processed/modified payloads.

{
 "0": { event 1 },
 "1": { event 2 }
 ...
 "n": { event n }
}

How will it behave in case of an error?

If one target fails, all the blocks will fail. But all targets will run. Possible solution: wrap the targets in a Try block with On Error Continue. (If you will use On Error Propagate, the result will be the same as without the Try block).

If one route fails the Scatter-Gather component throws an error of type MULE:COMPOSITE_ROUTING, not the original error. Although you can extract the original error from the MULE:COMPOSITE_ROUTING error.

Variable propagation

Each route will receive the same variable values. If one route modifies the variable first, it won’t affect the other routes (the original value will still be used).

If a variable is modified in more than one route that variable will be transformed into an array that will contain all the altered values of that particular variable.

If the variable is modified by a single route, the variable will keep the altered value.

Photo by Kolleen Gladden on Unsplash

Leave a Reply

Your email address will not be published. Required fields are marked *