-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
W-11939773-scatterGatherEdits-duke #2388
Open
dukesphere
wants to merge
17
commits into
v4.4
Choose a base branch
from
W-11939773-scatterGatherEdits-duke
base: v4.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
65e0b49
W-11939773-scatterGatherEdits-duke
dukesphere eac0773
Update modules/ROOT/pages/scatter-gather-concept.adoc
dukesphere f1db137
Update modules/ROOT/pages/scatter-gather-concept.adoc
dukesphere 756632b
Update modules/ROOT/pages/scatter-gather-concept.adoc
dukesphere 7fe5e53
W-11939773-scatterGatherEdits-duke
dukesphere 06d3c28
Update modules/ROOT/pages/scatter-gather-concept.adoc
dukesphere 381fc2b
W-11939773-scatterGatherEdits-duke
dukesphere 88ed6f6
W-11939773-scatterGatherEdits-duke
dukesphere 4b930ca
Update modules/ROOT/pages/scatter-gather-concept.adoc
dukesphere 2b5490f
W-11939773-scatterGatherEdits-duke
dukesphere 5a1771c
W-11939773-scatterGatherEdits-duke fix merge conflict
dukesphere 3ca33f3
W-11939773-scatterGatherEdits-duke add ex
dukesphere 33eb801
W-11939773-scatterGatherEdits-duke ex
dukesphere 6067884
W-11939773-scatterGatherEdits-duke ex
dukesphere db14177
W-11939773-scatterGatherEdits-duke ex
dukesphere fd17db9
W-11939773-scatterGatherEdits-duke ex
dukesphere 5595d6a
W-11939773-scatterGatherEdits-duke log error
dukesphere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,15 @@ include::_attributes.adoc[] | |
endif::[] | ||
:page-aliases: scatter-gather-xml-reference.adoc | ||
|
||
The Scatter-Gather component is a routing event processor that processes a Mule event through different parallel processing routes that contain different event processors. Each route receives a reference to the Mule event and executes a sequence of one or more event processors. Each of these routes uses a separate thread to execute the event processors, and the resulting Mule event can be either the same Mule event without modifications or a new Mule event with its own payload, attributes, and variables. The Scatter-Gather component then combines the Mule events returned by each processing route into a new Mule event that is passed to the next event processor only after every route completes successfully. | ||
The Scatter-Gather component (`<scatter-gather />`) is a routing event processor that processes a Mule event through different parallel processing routes that contain different event processors, which are connector operations or other Mule components. Each route receives a reference to the Mule event and executes a sequence of one or more event processors. Each of these routes uses a separate thread to execute the event processors, and the resulting Mule event can be either the same Mule event without modifications or a new Mule event with its own payload, attributes, and variables. The Scatter-Gather component then combines the Mule events returned by each processing route into a new Mule event that is passed to the next event processor only after every route completes successfully. | ||
|
||
The Scatter-Gather component executes each route in parallel, not sequentially. Parallel execution of routes can greatly increase the efficiency of your Mule application and may provide more information than sequential processing. | ||
The Scatter-Gather component executes each route in parallel, not sequentially. Parallel execution of routes can greatly increase the efficiency of your Mule application and can provide more information than sequential processing. | ||
|
||
The Scatter-Gather component works with repeatable streams. It does not process nonrepeatable streams, which can be read only once before they are lost. By default, all streams are repeatable in Mule unless a component's streaming strategy is configured to be nonrepeatable. | ||
<<<<<<< HEAD | ||
======= | ||
The Scatter-Gather component works with repeatable streams by default. It does not process nonrepeatable streams, which can be read only once before they are lost. By default, all streams are repeatable in Mule unless a component's streaming strategy is configured to be nonrepeatable. | ||
|
||
>>>>>>> 06d3c2889ac894b64ae2a1fef5e9d124956a0d56 | ||
The following diagram details the behavior of the Scatter-Gather component: | ||
|
||
image::mruntime-scatter-gather.png[Diagram of Scatter-Gather Component] | ||
|
@@ -23,24 +26,24 @@ WARNING: Configure your Scatter-Gather component to have at least two routes; ot | |
|
||
== Variable Propagation | ||
|
||
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, for example: | ||
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 an array of all the values defined for that variable within all the routes, for example: | ||
|
||
[source,xml,linenums] | ||
---- | ||
<set-variable variableName="var1" value="var1"/> | ||
<set-variable variableName="var2" value="var2"/> | ||
<scatter-gather doc:name="Scatter-Gather" doc:id="abc665e0-6119-4ecb-9f8b-52dbcbb1d488" > | ||
<route > | ||
<set-variable variableName="var2" value="newValue"/> | ||
<route > | ||
<set-variable variableName="var2" value="newValue"/> | ||
<set-variable variableName="var3" value="appleVal"/> | ||
</route> | ||
<route > | ||
<set-variable variableName="var3" value="bananaVal"/> | ||
</route> | ||
<route > | ||
<set-variable variableName="var3" value="otherVal"/> | ||
</route> | ||
<route > | ||
<set-variable variableName="var3" value="bananaVal"/> | ||
</route> | ||
<route > | ||
<set-variable variableName="var3" value="otherVal"/> | ||
<set-variable variableName="var4" value="val4"/> | ||
</route> | ||
</route> | ||
</scatter-gather> | ||
---- | ||
|
||
|
@@ -50,17 +53,19 @@ After aggregation, the variables are: | |
|
||
== Error Handling Inside Scatter-Gather Routes | ||
|
||
You can use a Try scope in each route of a Scatter-Gather component to handle any errors that might be generated by a route’s event processors. After every route executes, if any has failed with an error, then the Scatter-Gather component throws an error of type `MULE:COMPOSITE_ROUTING`, and event processing does not proceed past the Scatter-Gather component in the flow. Instead, the flow branches to your error-handling event processors. | ||
You can use a Try scope in each route of a Scatter-Gather component to handle any errors generated by a route’s event processors. After every route executes, if any failed with an error, the Scatter-Gather component throws an error of type `MULE:COMPOSITE_ROUTING`, and event processing does not proceed past the Scatter-Gather component in the flow. Instead, the flow branches to your error-handling event processors. | ||
|
||
Because the `MULE:COMPOSITE_ROUTING` error object gathers not only errors from routes that failed but also Mule events from successfully completed routes, your application can use the error-handling event processors to process Mule events from the routes that completed | ||
Because the `MULE:COMPOSITE_ROUTING` error object gathers not only errors from routes that failed but also Mule events from successfully completed routes, your application can use the error-handling event processors to process Mule events from the routes that completed. | ||
|
||
|
||
To illustrate how this works, consider the following two cases: | ||
|
||
* The routes in a Scatter-Gather component each contain a Try scope. + | ||
One of the routes generates an error that is successfully handled by that route’s Try scope through an `on-error-continue` error handler, so the route is completed successfully. The Scatter-Gather component consolidates the Mule events from all routes into a new Mule event and passes the consolidated event to the next event processor. | ||
* The routes in a Scatter-Gather component each contain a Try scope. | ||
+ | ||
One of the routes generates an error that is successfully handled by that route’s Try scope through an `on-error-continue` error handler, so the route completes successfully. The Scatter-Gather component consolidates the Mule events from all routes into a new Mule event and passes the consolidated event to the next event processor. | ||
|
||
* One of the routes in a Scatter-Gather component does not contain a Try scope or contains a Try scope with an error handler that cannot handle the error type, or the error handler is an `on-error-propagate` type. + | ||
* One of the routes in a Scatter-Gather component does not contain a Try scope or contains a Try scope with an error handler that cannot handle the error type, or the error handler is an `on-error-propagate` type: | ||
+ | ||
An error occurs in this route, causing the route to fail, which in turn causes the Scatter-Gather component to throw a `MULE:COMPOSITE_ROUTING` error. The flow branches to your error-handling event processors, which are able to process the Mule events from the completed routes. | ||
|
||
Example of handling these errors: | ||
|
@@ -69,14 +74,14 @@ Example of handling these errors: | |
<flow name="errorHandler"> | ||
<scatter-gather> | ||
<route> | ||
<raise-error type="APP:MYERROR"/> | ||
<raise-error type="APP:MYERROR" description="My Error Example"/> | ||
</route> | ||
<route> | ||
<set-payload value="apple"/> | ||
</route> | ||
</scatter-gather> | ||
<error-handler> | ||
<on-error-continue type="MULE:COMPOSITE_ROUTING"> | ||
<on-error-continue type="MULE:COMPOSITE_ROUTING"> | ||
<!-- This will have the error thrown by the first route --> | ||
<logger level="WARN" message="#[error.errorMessage.payload.failures['0']]"/> | ||
<!-- This will be a null value --> | ||
|
@@ -91,52 +96,88 @@ Example of handling these errors: | |
</flow> | ||
---- | ||
|
||
The Logger output looks like this (edited for readability): | ||
|
||
[source, logs] | ||
---- | ||
WARN ...LoggerMessageProcessor: | ||
org.mule.runtime.core.internal.message.ErrorBuilder$DeserializableErrorImplementation | ||
{ | ||
description=My Error | ||
detailedDescription=My Error | ||
errorType=APP:MYERROR | ||
cause=org.mule.runtime.api.exception.DefaultMuleException | ||
errorMessage=- | ||
suppressedErrors=[] | ||
childErrors=[] | ||
} | ||
WARN ...LoggerMessageProcessor: null | ||
WARN ...LoggerMessageProcessor: null | ||
WARN ...LoggerMessageProcessor: | ||
org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation | ||
{ | ||
payload=apple | ||
mediaType=*/* | ||
attributes=<not set> | ||
attributesMediaType=*/* | ||
} | ||
---- | ||
|
||
== Handle Timeout Errors in a Scatter-Gather | ||
|
||
If you configure a timeout for a Scatter-Gather component and a route does not complete processing before the timeout expires, the route throws a `MULE:TIMEOUT` error. This error is then handled the same way as any other error generated from a route: after each route completes (either by processing success or by throwing a `MULE:TIMEOUT` error), the successful results and errors are collected together in the Scatter-Gather component `MULE:COMPOSITE_ROUTING` error, which is then processed in your configured error handler. | ||
If you configure a timeout for a Scatter-Gather component and a route does not complete processing before the timeout expires, the route throws a `MULE:TIMEOUT` error. This error is then handled the same way as any other error generated from a route: after each route completes (either by processing successfully or by throwing a `MULE:TIMEOUT` error), the successful results and errors are collected into the Scatter-Gather component `MULE:COMPOSITE_ROUTING` error, which is then processed in your configured error handler. | ||
|
||
== Example Project | ||
In Anypoint Studio, you can download and open the example project _Scatter-Gather Flow Control_ from Anypoint Exchange to learn more about how to use the Scatter-Gather component. This example shows the usage of the scatter-gather control flow to aggregate data in parallel and return the result in JSON. | ||
In Anypoint Studio, you can download and open the example project https://www.mulesoft.com/exchange/org.mule.examples/scatter-gather-flow-control/[Scatter-Gather Flow Control^] from Anypoint Exchange to learn more about how to use the Scatter-Gather component. This example shows the use of the scatter-gather control flow to aggregate data in parallel and return the result in JSON. | ||
|
||
The example uses prepared data as input for two resources that should be aggregated. The data represents information about two contacts and has the following structure: | ||
The example uses prepared data as input for two resources to be aggregated. The data represents information about two contacts and has the following structure: | ||
|
||
|=== | ||
|Resource|`firstname`|`surname`|`phone`|`email` | ||
|contacts-1.csv | ||
|John | ||
|Doe | ||
|096548763 | ||
|[email protected] | ||
|+[email protected]+ | ||
|
||
|contacts-2.csv | ||
|Jane | ||
|Doe | ||
|091558780 | ||
|[email protected] | ||
|+[email protected]+ | ||
|=== | ||
|
||
DataWeave is used to aggregate the data. The information about the contacts is aggregated to a JSON structure that represents data from both resources. | ||
The example uses DataWeave to aggregate the data. The contact information is aggregated to a JSON structure that represents data from both resources. | ||
|
||
To download and open this example project through Anypoint Studio, click the Exchange icon in the upper-left corner. Then, in the window that opens, log into Anypoint Exchange and search on the name of the project. | ||
|
||
To download and open this example project while you are in Anypoint Studio, click the Exchange icon in the upper-left corner. Then, in the window that opens, log into Anypoint Exchange and search on the name of the project. | ||
== Repeatable Stream Input | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IvanAndresFritzler This new section re repeatable streams replaces previous content from the introduction. |
||
The Scatter-Gather component can process only repeatable streams. Scatter-Gather cannot process a non-repeatable stream as input from an upstream component. | ||
dukesphere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Repeatable streams are a Mule feature that enables a component to re-read a stream. Non-repeatable streams can be read only once before they are lost. | ||
|
||
By default, Mule components return a repeatable stream unless their streaming strategy is configured to be non-repeatable. | ||
|
||
== Scatter-Gather XML Reference | ||
|
||
[%header%autowidth.spread,cols="a,a"] | ||
|=== | ||
|Element |Description | ||
| `scatter-gather` |Sends a request message to multiple targets concurrently. It collects the responses from all routes, and aggregates them into a single message. | ||
| `scatter-gather` |Sends a request message to multiple targets concurrently. This scope collects the responses from all routes and aggregates them into a single message. | ||
2+| *Attributes* | ||
|`timeout` |Sets the timeout for responses from sent messages, in milliseconds. A value of 0 or lower than 0 means no timeout. | ||
|`timeout` |Sets the timeout for responses from sent messages, in milliseconds. A value of 0 or less than 0 means no timeout. | ||
|
||
| `maxConcurrency` |Determines the maximum number of concurrent routes to process. | ||
|
||
| `maxConcurrency` |Determines the maximum amount of concurrent routes to process. + | ||
By default all routes run in parallel. | ||
* By default all routes run in parallel. | ||
|
||
By setting this value to 1, scatter-gather processes the routes sequentially. | ||
* By setting this value to 1, `scatter-gather` processes the routes sequentially. | ||
|
||
| `target` | The name of the target variable. | ||
| `target` | The name of the xref:target-variables.adoc[target variable]. | ||
|
||
| `targetValue` | Value of the data to store in the target variable. + | ||
If not set, the default value is `#[payload]`. + | ||
| `targetValue` | Value of the data to store in the target variable. | ||
If not set, the default value is `#[payload]`. | ||
This field accepts any value that a variable accepts: | ||
|
||
* Any supported data type. | ||
|
@@ -158,7 +199,8 @@ This field accepts any value that a variable accepts: | |
|
||
== See Also | ||
|
||
* xref:about-components.adoc[Core Components] | ||
* xref:about-components.adoc[] | ||
* xref:transaction-management.adoc#tx_scopes_routers[How Transactions Affect Scopes and Routers] | ||
* xref:error-handling.adoc[Error Handling] | ||
* xref:try-scope-concept.adoc[Try Scope] | ||
* xref:error-handling.adoc[] | ||
* xref:try-scope-concept.adoc[] | ||
* xref:about-mule-event.adoc[] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IvanAndresFritzler will check this
The issue is actually the empty On Error Propagate data that returns after calling the Raise Error component in the component.