Scatter Gather Mediator¶
The Scatter Gather Mediator can be used to clone a message into several messages and aggregate the responses. It resembles the Scatter-Gather enterprise integration pattern.
Syntax¶
<scatter-gather parallel-execution=(true | false) target=(Body | Variable) target-variable=(string) result-content-type=(JSON | XML) result-enclosing-element=(string)>
<aggregation expression="expression" condition="expression" timeout="long" min-messages="expression" max-messages="expression"/>
<sequence>
(mediator)+
</sequence>+
</scatter-gather>
Configuration¶
The parameters available to configure the Scatter Gather mediator are as follows.
General Configurations¶
Parameter Name | Description |
---|---|
Parallel Execution |
Specifies whether the sequences should execute in parallel or sequentially.
|
Aggregate Configurations¶
Parameter Name | Description |
---|---|
Content Type |
Specifies the format of the aggregated result. Supported values:
|
Result Enclosing Element Name | Specifies the name of the root element wrapping the aggregation result. Applicable only when Content Type is XML. |
Aggregate Entire Payloads | By default, the entire message payload is aggregated across all flows. If you prefer to aggregate only specific parts of the payload, disable this option and specify the required portions using an expression. |
Partial payload to Aggregate | Specifies the expression that defines which part of the message payload should be aggregated. This parameter is applicable only when Aggregate Entire Payloads is disabled. |
Filter Messages for Aggregation | By default, all messages are aggregated. Enable this option to filter messages based on a specified condition before aggregation. |
Condition | Defines the condition used to filter which responses should be included in the final aggregation. To prevent indefinite waiting, either a Completion Timeout or a Minimum flows to complete value must be configured under Advanced configurations. |
Advanced Configurations¶
Parameter Name | Description |
---|---|
Completion Timeout | Specifies the maximum duration (in milliseconds) to wait for flows to complete aggregation before timing out. |
Minimum flows to complete | Specifies the minimum number of flows that must be completed before aggregation can proceed. |
Maximum flows to complete | Specifies the maximum number of flows that should be processed for aggregation. |
Output Configurations¶
Parameter Name | Description |
---|---|
Overwrite Message Body | By default, replaces the message body with the aggregated response from the Scatter Gather mediator. You can disable this option and specify a variable name to store the aggregated response instead. |
Output Variable Name | Specifies the variable name to store the output of the Scatter Gather mediator. This is applicable only when Overwrite Message Body is disabled. |
Example¶
In this example, the Scatter Gather mediator execute the sequences parallelly and replace the message body with the aggregated JSON result.
<scatter-gather parallel-execution="true" target="Body" result-content-type="JSON">
<aggregation expression="${payload}" />
<sequence>
<log category="INFO">
<message>Processing message in clone path 1</message>
</log>
<payloadFactory media-type="json" template-type="default">
<format>{
"requestId": ${payload.requestId},
"pet": {
"name": "pet2",
"type": "cat"
},
"status": true
}</format>
</payloadFactory>
</sequence>
<sequence>
<log category="INFO">
<message>Processing message in clone path 2</message>
</log>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:5454/api/pet"/>
</endpoint>
</call>
</sequence>
</scatter-gather>
In this example, the Scatter Gather work in sequential mode and save the aggregated XML result to a variable named servicesResult
.
<scatter-gather parallel-execution="false" target="Variable" target-variable="servicesResult" result-content-type="XML" result-enclosing-element="AggregatedResults">
<aggregation expression="xpath('$body/node()')" />
<sequence>
<log category="INFO">
<message>Processing message in clone path 1</message>
</log>
<call>
<endpoint>
<address uri="http://service1.example.com" />
</endpoint>
</call>
</sequence>
<sequence>
<log category="INFO">
<message>Processing message in clone path 2</message>
</log>
<call>
<endpoint>
<address uri="http://service2.example.com" />
</endpoint>
</call>
</sequence>
</scatter-gather>