MuleSoft Scatter-Gather Integration Pattern with Example

  • In this article we will be discussing an Enterprise Integration Pattern for Message Routing called the Scatter-Gather.
  • Scatter-Gather is a Message routing pattern which broadcasts messages to multiple recipients and aggregates the response back in a single message.
  • In simple words, the messages are executed in parallel (scatter) and response from each execution is bundled (gathered) as one single message.
  • More than one process is required for Scatter-Gather to function according to its discussed merits.
Mule Scatter-Gather Router
What is Scatter-Gather Integration Pattern?

Scatter-Gather processes messages in-parallel and the result is an aggregated response of the routes.

How does Scatter-Gather Integration Pattern work?

Scatter-Gather Integration Pattern executes the messages in parallel (concurrent processing). It sends the messages to all the routes/flows at the same time through a parallel thread pool. While a particular message is being processed, the remaining messages should wait for the completion of the message. In other words, the Scatter-Gather processing will be completed only when all the messages are fully processed by rest of routes/flows.

What is the total time taken for the completion of the Scatter-Gather process in multiple flows?

Suppose we have 3 flows/routes executed with Scatter-Gather Integration pattern and take time e.g. Process 1 = 20 sec, Process 2 = 14 sec and Process 3 = 10 sec. Then total time taken for the completion will be 20 sec.

Why use the Scatter-Gather Integration Pattern?

Use Scatter-Gather for multicasting scenarios. In cases where the process responses are independent to each other, parallel processing can be efficiently executed. If we use sequential processing, in case of one message/process failure the complete processing will come to halt. This may be a valid business scenario to end the process, whereas in case of scatter-gather the responses will include or exclude the error cases (scenario based) therefore avoiding a complete meltdown.

Does Scatter-Gather halt the processing of the messages if any one of the routing processes fail?

False, Scatter-Gather doesn’t halt the processes if error handling in place, the route/flow which throws error it can be handled and aggregates the results as output.

What happens to the initial payload, when one of the processes in the Scatter-Gather fails?

Failure in one route does not stop Scatter-Gather from sending messages to its other configured routes, so it is possible that many or all routes may fail concurrently. If and when some of the route fails, Scatter-Gather performs the below operations: Sets the exception payload accordingly for each route.

What happens if the variable in one process is modified and not in the other?

Every route starts with the same initial variable values. Modifications to a variable within a specific route do not affect other routes. So, if a variable is added or modified in one route, then, after aggregation, the value is defined by that route. If a variable is added or modified by more than one route, the value is added to a list of all the values defined for that variable within all the routes.

How Scatter-Gather Router Works

In this working tutorial we will learn to implement the scatter gather router with in the mulitple flows and sub-flows. Also, we will discuss Error Handling in scatter gather router step by step.

Note: When a particular message processed, the remaining messages should wait for the completion of the message. In other words, the scatter gather router processing completes only when all the messages fully processed. Suppose in following implementation we have 3 routes/flows (Process 1, Process 2 and Process 3).

Scatter-Gather Process 1 Completed (Green)

In below flow diagram, scatter gather Process 1 completed (Green), while other two processes (Process 2 and Process 3) are work in-progress (Yellow). The response not yet captured (Red).

How Scatter-Gather works?

Scatter-Gather Process 1 and Process 2 Completed (Green)

In below flow diagram, scatter gather Process 1 and Process 2 completed (Green), while other process (Process 3) is work in-progress (Yellow). The response not yet captured (Red).

Scatter-Gather Process 1, Process 2 and Process 3 Completed (All Green)

In below flow diagram, scatter gather Process1, Process 2 and Process 3 completed (All Green). Hence, The response captured/aggregate as a bundle of all three responses (Green).

How Scatter-Gather works?

Scatter-Gather Router Example

  • Suppose, the Scatter-Gather having the following 3 flows/routes (FlowOne, FlowTwo, and FlowThree).
  • Payloads modified to support a simple addition, subtraction and division of two numbers (example: 7+2, 7-2, 30/2) aggregate as an output result of each flow.
  • In the screenshot below, results displayed as expected.
Scatter-Gather Router Example
Scatter Gather Example

Application Logs (Scatter-Gather Output Payload)

**********************************************************************
INFO  2021-08-12 20:41:59,502 [Mule.app.deployer.monitor.1.thread.1] org.mule.runtime.core.internal.logging.LogUtil: 
**********************************************************************
* Started app 'mule-scatter-gather-example'                          *
* Application plugins:                                               *
*  - Sockets : 1.1.5                                                 *
*  - HTTP : 1.5.11                                                   *
**********************************************************************
INFO  2021-08-12 20:43:50,741 [[MuleRuntime].cpuLight.03: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @c8167cd] [event: e63c1e10-fb7f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
 FlowOne payload {
  "result0": 123
}
INFO  2021-08-12 20:43:50,744 [[MuleRuntime].cpuLight.02: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @c8167cd] [event: e63c1e10-fb7f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
 FlowThree payload {
  "result0": 123
}
INFO  2021-08-12 20:43:50,746 [[MuleRuntime].cpuLight.04: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @c8167cd] [event: e63c1e10-fb7f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
 FlowTwo payload {
  "result0": 123
}
INFO  2021-08-12 20:43:50,799 [[MuleRuntime].cpuLight.02: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @c8167cd] [event: e63c1e10-fb7f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: {
  "0": {
    "inboundAttachmentNames": [
      
    ],
    "exceptionPayload": null,
    "inboundPropertyNames": [
      
    ],
    "outboundAttachmentNames": [
      
    ],
    "payload": {
      "FlowOne: Addition (7+2) ": 9
    },
    "outboundPropertyNames": [
      
    ],
    "attributes": {
      "headers": {
        "host": "localhost:8085",
        "connection": "keep-alive",
        "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
        "cache-control": "no-cache",
        "sec-ch-ua-mobile": "?0",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
        "postman-token": "bfed878a-7d7c-0a48-2210-257edd562385",
        "accept": "*/*",
        "sec-fetch-site": "none",
        "sec-fetch-mode": "cors",
        "sec-fetch-dest": "empty",
        "accept-encoding": "gzip, deflate, br"
        },
      "clientCertificate": null,
      "method": "GET",
      "scheme": "http",
      "queryParams": {
        
      },
      "requestUri": "/testScatterGather",
      "queryString": "",
      "version": "HTTP/1.1",
      "maskedRequestPath": null,
      "listenerPath": "/testScatterGather",
      "localAddress": "/127.0.0.1:8085",
      "relativePath": "/testScatterGather",
      "uriParams": {
        
      },
      "rawRequestUri": "/testScatterGather",
      "rawRequestPath": "/testScatterGather",
      "remoteAddress": "/127.0.0.1:61199",
      "requestPath": "/testScatterGather"
    }
  },
  "2": {
    "inboundAttachmentNames": [
      
    ],
    "exceptionPayload": null,
    "inboundPropertyNames": [
      
    ],
    "outboundAttachmentNames": [
      
    ],
    "payload": {
      "FlowThree: Division (30/2) ": 15.0
    },
    "outboundPropertyNames": [
      
    ],
    "attributes": {
      "headers": {
        "host": "localhost:8085",
        "connection": "keep-alive",
        "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
        "cache-control": "no-cache",
        "sec-ch-ua-mobile": "?0",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
        "postman-token": "bfed878a-7d7c-0a48-2210-257edd562385",
        "accept": "*/*",
        "sec-fetch-site": "none",
        "sec-fetch-mode": "cors",
        "sec-fetch-dest": "empty",
        "accept-encoding": "gzip, deflate, br"
        },
      "clientCertificate": null,
      "method": "GET",
      "scheme": "http",
      "queryParams": {
        
      },
      "requestUri": "/testScatterGather",
      "queryString": "",
      "version": "HTTP/1.1",
      "maskedRequestPath": null,
      "listenerPath": "/testScatterGather",
      "localAddress": "/127.0.0.1:8085",
      "relativePath": "/testScatterGather",
      "uriParams": {
        
      },
      "rawRequestUri": "/testScatterGather",
      "rawRequestPath": "/testScatterGather",
      "remoteAddress": "/127.0.0.1:61199",
      "requestPath": "/testScatterGather"
    }
  }
}
INFO  2021-08-12 20:43:50,808 [[MuleRuntime].cpuLight.02: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @c8167cd] [event: e63c1e10-fb7f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Test Variable value : Test Variable 123
INFO  2021-08-12 20:43:50,828 [[MuleRuntime].cpuIntensive.04: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_INTENSIVE @1cd96d1f] [event: e63c1e10-fb7f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation
{
  payload=org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider@639c2342
  mediaType=application/json; charset=UTF-8
  attributes=<not set>
  attributesMediaType=*/*
}        

Error Handling in Scatter-Gather Router Example

  • Suppose, the Scatter-Gather having the following 3 flows/routes (FlowOne, FlowTwo, and FlowThree).
  • Payloads modified to support a simple addition, subtraction and division of two numbers (example: 7+2, 7-2, 30/0) aggregate as an output result of each flow.
    • But, FlowThree will throw an exception/error, hence we are surrounding it with try-catch and on-error-continue scope as below.
    <?xml version="1.0" encoding="UTF-8"?>
    
    <mule xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
    http://www.mulesoft.org/schema/mule/wsc http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd">
    	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="333571c7-abe4-439b-8d3d-86a230d19830">
    		<http:listener-connection host="0.0.0.0" port="8085" />
    	</http:listener-config>
    	<flow name="mule-scatter-gather-flow" doc:id="3eb3e027-11a2-4b80-b908-b683e4645e82">
    		<http:listener doc:name="Listener" doc:id="dde3e061-14e2-4b66-ba9d-d4721f8ec35a" config-ref="HTTP_Listener_config" path="/testScatterGather" allowedMethods="GET" />
    		<set-variable value='#["Test Variable 123"]' doc:name="Set Variable" doc:id="7ef6e202-3dc7-4e5c-84ca-eab5af23718a" variableName="testVar" />
    		<set-payload value='#[%dw 2.0
    			output application/json
    			---
    			{
    				"result0" : 123
    			}]' doc:name="Set Payload" doc:id="ad2019b6-9939-400b-9311-8fc6cbc456fc" />
    		<scatter-gather doc:name="Scatter-Gather" doc:id="736209fd-7a32-434a-b8b1-a9c1631e686a">
    			<route>
    				<try doc:name="Try" doc:id="0afd15cd-d7c7-47cb-8efb-266c5eae8005">
    					<logger level="INFO" doc:name="Flow1 Payload Logger" doc:id="11b9dd89-6624-4af4-a591-efe6e63c19fa" message="#['\n FlowOne payload #[payload]']" />
    					<flow-ref doc:name="FlowOne" doc:id="3d4c6eac-b795-4aa5-8d61-55d14202a66d" name="FlowOne" />
    					<error-handler>
    						<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="ee2ddeae-d50d-469a-9a35-a5ad0fa4cb1d">
    							<ee:transform doc:name="FlowOne Error Message" doc:id="e192345c-8498-46c6-a5be-391005ceedb1">
    								<ee:message>
    									<ee:set-payload><![CDATA[%dw 2.0
    									output application/java
    									---
    									[]]]></ee:set-payload>
    								</ee:message>
    							</ee:transform>
    						</on-error-continue>
    					</error-handler>
    				</try>
    			</route>
    			<route>
    				<try doc:name="Try" doc:id="387345d0-174d-4fe5-ac47-8cc175786b60">
    					<logger level="INFO" doc:name="Flow 2 Payload logger" doc:id="e83b0a75-78ed-45e5-8757-75205f55c3ee" message="#['\n FlowTwo payload #[payload]']" />
    					<flow-ref doc:name="FlowTwo" doc:id="0bdaf8a0-9d08-4ce3-b4cd-b53f31190a90" name="FlowTwo" />
    					<error-handler>
    						<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="afefe4b5-c1b9-4694-b623-34415618ec10">
    							<ee:transform doc:name="FlowTwo Error Message" doc:id="528a1eb7-0051-4cd0-9304-a2fa03582a6a">
    								<ee:message>
    									<ee:set-payload><![CDATA[%dw 2.0
    									output application/java
    									---
    									[]]]></ee:set-payload>
    								</ee:message>
    							</ee:transform>
    						</on-error-continue>
    					</error-handler>
    				</try>
    			</route>
    			<route>
    				<try doc:name="Try" doc:id="b65dff1c-d99c-4bc2-b4e5-baca52938b7c">
    					<logger level="INFO" doc:name="Flow 3 Payload Logger" doc:id="db7ab89d-547f-4fc9-b705-603ef8753d1c" message="#['\n FlowThree payload #[payload]']" />
    					<flow-ref doc:name="FlowThree" doc:id="8ab949a1-ae25-403a-881c-ea9d72105d25" name="FlowThree" />
    					<error-handler>
    						<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="08c03634-2ae1-4279-8fdb-41d65e5812db">
    							<ee:transform doc:name="FlowThree Error Message" doc:id="064c7346-03a1-45ec-9136-8d8cc8a1a9c0">
    								<ee:message>
    									<ee:set-payload><![CDATA[%dw 2.0
    									output application/json
    									---
    									{
    										"FlowThreeError" : (error.errorType.namespace default "")  ++ ':' ++ (error.errorType.identifier default "") 
    									}
    									]]></ee:set-payload>
    								</ee:message>
    							</ee:transform>
    						</on-error-continue>
    					</error-handler>
    				</try>
    			</route>
    		</scatter-gather>
    		<logger level="INFO" doc:name="Logger" doc:id="082c149b-89b1-4aa0-abdf-befab180ab12" message="#[%dw 2.0
    				output application/json
    					---
    				payload]" />
    		<logger level="INFO" doc:name="Logger" doc:id="65c39c55-c432-4291-89f4-93a902f62d66" message='#["Test Variable value : " ++ vars.testVar]' />
    		<ee:transform doc:name="Transform Message" doc:id="573ab50a-1e67-4400-9c4d-0f9c89fc6623">
    			<ee:message>
    				<ee:set-payload><![CDATA[%dw 2.0
    					output application/json
    					---
    					flatten(payload..payload)]]></ee:set-payload>
    			</ee:message>
    		</ee:transform>
    		<logger level="INFO" doc:name="Logger" doc:id="5ac6f253-a187-49aa-993a-3aa426f21098" />
    	</flow>
    	<sub-flow name="FlowOne" doc:id="3fdc08e6-d47c-4dc2-8411-a0b5083a180e">
    		<set-payload value='#[%dw 2.0
    			output application/json
    			---
    			{
    				"FlowOne: Addition (7+2) " : 7+2
    			}]' doc:name="FlowOnePayload" doc:id="47102572-208a-48eb-b51f-4aa1fee9ade3" />
    	</sub-flow>
    	<sub-flow name="FlowTwo" doc:id="09863a50-384d-4543-8c21-8898d5f92562">
    		<set-payload value='#[%dw 2.0
    			output application/json
    			---
    			{
    				"FlowTwo: Subtraction (7-2) " : 7-2
    			}]' doc:name="FlowTwoPayload" doc:id="e6ca4c6c-65e0-4622-84fd-be3adea9a0cd" />
    	</sub-flow>
    	<sub-flow name="FlowThree" doc:id="5d4ea8ae-fe65-452f-8b10-4b976738cb20">
    		<set-payload value='#[%dw 2.0
    			output application/json
    			---
    			{
    				"FlowThree: Division (30/0) " : 30/0
    			}]' doc:name="FlowThreePayload" doc:id="1a016528-d449-4eaa-a89e-4a0f1722eba2" />
    	</sub-flow>
    </mule>
    Scatter Gather with On Error Continue

    Application Logs (Scatter-Gather Output Payload)

    **********************************************************************
    INFO  2021-08-12 21:18:01,952 [Mule.app.deployer.monitor.1.thread.1] org.mule.runtime.core.internal.logging.LogUtil: 
    **********************************************************************
    * Started app 'mule-scatter-gather-example'                          *
    * Application plugins:                                               *
    *  - Sockets : 1.1.5                                                 *
    *  - HTTP : 1.5.11                                                   *
    **********************************************************************
    INFO  2021-08-12 21:20:53,756 [[MuleRuntime].cpuLight.03: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @4ca7d1a8] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
     FlowOne payload {
      "result0": 123
    }
    INFO  2021-08-12 21:20:53,757 [[MuleRuntime].cpuLight.04: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @4ca7d1a8] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
     FlowTwo payload {
      "result0": 123
    }
    INFO  2021-08-12 21:20:53,757 [[MuleRuntime].cpuLight.08: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @4ca7d1a8] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
     FlowThree payload {
      "result0": 123
    }
    ERROR 2021-08-12 21:20:53,763 [[MuleRuntime].cpuLight.08: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @4ca7d1a8] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.exception.OnErrorContinueHandler: 
    ********************************************************************************
    Message               : "Division by zero
    
    1| %dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }
                                                                                          ^^^^
    Trace:
      at main (line: 1, column: 84)" evaluating expression: "%dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }".
    Error type            : MULE:EXPRESSION
    Element               : FlowThree/processors/0 @ mule-scatter-gather-example:mule-scatter-gather-example.xml:117 (FlowThreePayload)
    Element XML           : <set-payload value="#[%dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }]" doc:name="FlowThreePayload" doc:id="1a016528-d449-4eaa-a89e-4a0f1722eba2"></set-payload>
    
      (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
    ********************************************************************************
    
    INFO  2021-08-12 21:20:53,795 [[MuleRuntime].cpuIntensive.05: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_INTENSIVE @7abbf325] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: {
      "0": {
        "inboundAttachmentNames": [
          
        ],
        "exceptionPayload": null,
        "inboundPropertyNames": [
          
        ],
        "outboundAttachmentNames": [
          
        ],
        "payload": {
          "FlowOne: Addition (7+2) ": 9
        },
        "outboundPropertyNames": [
          
        ],
        "attributes": {
          "headers": {
            "host": "localhost:8085",
            "connection": "keep-alive",
            "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
            "cache-control": "no-cache",
            "sec-ch-ua-mobile": "?0",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
            "postman-token": "6edb2bcd-8b83-12c7-6b74-3890a0e5feb7",
            "accept": "*/*",
            "sec-fetch-site": "none",
            "sec-fetch-mode": "cors",
            "sec-fetch-dest": "empty",
            "accept-encoding": "gzip, deflate, br"
            },
          "clientCertificate": null,
          "method": "GET",
          "scheme": "http",
          "queryParams": {
            
          },
          "requestUri": "/testScatterGather",
          "queryString": "",
          "version": "HTTP/1.1",
          "maskedRequestPath": null,
          "listenerPath": "/testScatterGather",
          "localAddress": "/127.0.0.1:8085",
          "relativePath": "/testScatterGather",
          "uriParams": {
            
          },
          "rawRequestUri": "/testScatterGather",
          "rawRequestPath": "/testScatterGather",
          "remoteAddress": "/127.0.0.1:60739",
          "requestPath": "/testScatterGather"
        }
      },
      "1": {
        "inboundAttachmentNames": [
          
        ],
        "exceptionPayload": null,
        "inboundPropertyNames": [
          
        ],
        "outboundAttachmentNames": [
          
        ],
        "payload": {
          "FlowTwo: Subtraction (7-2) ": 5
        },
        "outboundPropertyNames": [
          
        ],
        "attributes": {
          "headers": {
            "host": "localhost:8085",
            "connection": "keep-alive",
            "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
            "cache-control": "no-cache",
            "sec-ch-ua-mobile": "?0",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
            "postman-token": "6edb2bcd-8b83-12c7-6b74-3890a0e5feb7",
            "accept": "*/*",
            "sec-fetch-site": "none",
            "sec-fetch-mode": "cors",
            "sec-fetch-dest": "empty",
            "accept-encoding": "gzip, deflate, br"
            },
          "clientCertificate": null,
          "method": "GET",
          "scheme": "http",
          "queryParams": {
            
          },
          "requestUri": "/testScatterGather",
          "queryString": "",
          "version": "HTTP/1.1",
          "maskedRequestPath": null,
          "listenerPath": "/testScatterGather",
          "localAddress": "/127.0.0.1:8085",
          "relativePath": "/testScatterGather",
          "uriParams": {
            
          },
          "rawRequestUri": "/testScatterGather",
          "rawRequestPath": "/testScatterGather",
          "remoteAddress": "/127.0.0.1:60739",
          "requestPath": "/testScatterGather"
        }
      },
      "2": {
        "inboundAttachmentNames": [
          
        ],
        "exceptionPayload": null,
        "inboundPropertyNames": [
          
        ],
        "outboundAttachmentNames": [
          
        ],
        "payload": {
          "FlowThreeError": "MULE:EXPRESSION"
        },
        "outboundPropertyNames": [
          
        ],
        "attributes": {
          "headers": {
            "host": "localhost:8085",
            "connection": "keep-alive",
            "sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
            "cache-control": "no-cache",
            "sec-ch-ua-mobile": "?0",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
            "postman-token": "6edb2bcd-8b83-12c7-6b74-3890a0e5feb7",
            "accept": "*/*",
            "sec-fetch-site": "none",
            "sec-fetch-mode": "cors",
            "sec-fetch-dest": "empty",
            "accept-encoding": "gzip, deflate, br"
            },
          "clientCertificate": null,
          "method": "GET",
          "scheme": "http",
          "queryParams": {
            
          },
          "requestUri": "/testScatterGather",
          "queryString": "",
          "version": "HTTP/1.1",
          "maskedRequestPath": null,
          "listenerPath": "/testScatterGather",
          "localAddress": "/127.0.0.1:8085",
          "relativePath": "/testScatterGather",
          "uriParams": {
            
          },
          "rawRequestUri": "/testScatterGather",
          "rawRequestPath": "/testScatterGather",
          "remoteAddress": "/127.0.0.1:60739",
          "requestPath": "/testScatterGather"
        }
      }
    }
    INFO  2021-08-12 21:20:53,801 [[MuleRuntime].cpuIntensive.05: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_INTENSIVE @7abbf325] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Test Variable value : Test Variable 123
    INFO  2021-08-12 21:20:53,819 [[MuleRuntime].cpuIntensive.05: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_INTENSIVE @7abbf325] [event: 134233e1-fb85-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
    org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation
    {
      payload=org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider@3172b7c3
      mediaType=application/json; charset=UTF-8
      attributes=<not set>
      attributesMediaType=*/*
    }

    What would be the result of Scatter-Gather if “On-Error propagates” used instead of “On-Error continue” when one of the routes fails?

    • As I mentioned in my previous blog remember “On-Error propagates – RED in RED Out” error handling technique.
    • Blog’s Reference: Mule 4 + MuleSoft + Error Handling Techniques + Examples
    • In this scenario an error response “Error type : MULE:EXPRESSION – Division by zero” returned to the end user.
    <route>
    	<try doc:name="Try" doc:id="b65dff1c-d99c-4bc2-b4e5-baca52938b7c">
    					<logger level="INFO" doc:name="Flow 3 Payload Logger" doc:id="db7ab89d-547f-4fc9-b705-603ef8753d1c" message="#['\n FlowThree payload #[payload]']" />
    					<flow-ref doc:name="FlowThree" doc:id="8ab949a1-ae25-403a-881c-ea9d72105d25" name="FlowThree" />
    					<error-handler>
    						<on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="08c03634-2ae1-4279-8fdb-41d65e5812db">
    							<ee:transform doc:name="FlowThree Error Message" doc:id="064c7346-03a1-45ec-9136-8d8cc8a1a9c0">
    								<ee:message>
    									<ee:set-payload><![CDATA[%dw 2.0
    									output application/json
    									---
    									{
    										"FlowThreeError" : (error.errorType.namespace default "")  ++ ':' ++ (error.errorType.identifier default "") 
    									}
    									]]></ee:set-payload>
    								</ee:message>
    							</ee:transform>
    						</on-error-propagate>
    					</error-handler>
    	</try>
    </route>
    Scatter Gather with On Error Propagate Scope

    Application Logs (Scatter-Gather Output Payload)

    **********************************************************************
    INFO  2021-08-12 22:35:24,805 [[MuleRuntime].cpuLight.04: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @6116c2b2] [event: 7c3475c0-fb8f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
     FlowTwo payload {
      "result0": 123
    }
    INFO  2021-08-12 22:35:24,805 [[MuleRuntime].cpuLight.02: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @6116c2b2] [event: 7c3475c0-fb8f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
     FlowThree payload {
      "result0": 123
    }
    ERROR 2021-08-12 22:35:24,823 [[MuleRuntime].cpuLight.02: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @6116c2b2] [event: 7c3475c0-fb8f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
    ********************************************************************************
    Message               : "Division by zero
    
    1| %dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }
                                                                                          ^^^^
    Trace:
      at main (line: 1, column: 84)" evaluating expression: "%dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }".
    Error type            : MULE:EXPRESSION
    Element               : FlowThree/processors/0 @ mule-scatter-gather-example:mule-scatter-gather-example.xml:117 (FlowThreePayload)
    Element XML           : <set-payload value="#[%dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }]" doc:name="FlowThreePayload" doc:id="1a016528-d449-4eaa-a89e-4a0f1722eba2"></set-payload>
    
      (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
    ********************************************************************************
    
    INFO  2021-08-12 22:35:24,837 [[MuleRuntime].cpuLight.03: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @6116c2b2] [event: 7c3475c0-fb8f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
     FlowOne payload {
      "result0": 123
    }
    ERROR 2021-08-12 22:35:24,849 [[MuleRuntime].cpuLight.03: [mule-scatter-gather-example].mule-scatter-gather-flow.CPU_LITE @6116c2b2] [event: 7c3475c0-fb8f-11eb-8573-a44cc84ce10c] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: Exception(s) were found for route(s): 
    Route 2: Caught exception in Exception Strategy: "Division by zero
    
    1| %dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }
                                                                                          ^^^^
    Trace:
      at main (line: 1, column: 84)" evaluating expression: "%dw 2.0    output application/json    ---    {     "FlowThree: Division (30/0) " : 30/0    }".

    Thank you for reading. Have a great day 🙂