cSplitter
differently in individual routes.
cSplitter Standard properties
These properties are used to configure cSplitter running in the Standard Job framework.
The Standard
cSplitter component belongs to the Routing family.
Basic settings
Language | Select the language of the expression you want to use to split your messages, from None, Constant, EL, Groovy, Header, JavaScript, JoSQL, JSonPath, JXPath, MVEL, OGNL, PHP, Property, Python, Ruby, Simple, SpEL, SQL, XPath, and XQuery. |
Correlation expression/Expression |
Type in the expression to use to split the messages. |
Correlation expression/Use Result Class Type |
This option appears when XPath is Select this check box to set the result type of the sub-messages |
Correlation expression/Add Namespaces |
This option appears when XPath is Select this check box to add namespaces for the Xpath expression. |
Use Strategy | Select this check box to refer to an aggregation strategy to assemble the replies from the sub-messages into a single outgoing message from the splitter. Enter the ID of the aggregation strategy in the Strategy field. The sub-message replies will be aggregated in the order they come back if Streaming is enabled. If not, the sub-message replies will be aggregated in the same order as they were split. |
Parameters/Parallel Processing |
Select this check box to process the sub-messages concurrently. The caller thread will wait until all sub-messages have been fully processed before it continues. |
Parameters/Stop on Exception |
Select this check box to stop processing immediately when an exception occurs. |
Parameters/Streaming | Select this check box to split the message in a streaming fashion, which means it will split the input message in chunks. It is recommended to enable this option when processing big messages. |
Parameters/Share Unit of Work |
Select this check box to share the unit of work between the parent exchange and each split exchange. For more information and an use case of this option, see the site http://camel.apache.org/splitter.html. |
Parameters/Timeout | Specify a total timeout in millisecond. If the message is not split and processed within the given time frame, the timeout triggers and the splitter breaks out. |
Usage
Usage rule |
cSplitter is used as a middle |
Connections |
split: Select this link to route the split messages to the next endpoint. |
Route: Select this link to route all the messages from the sender to the next endpoint. |
|
Limitation |
n/a |
Scenario: Using cSplitter to split a message and aggregate replies from
sub-messages
This scenario applies only to a Talend solution with ESB.
In this scenario, we will use the cSplitter component
to split a message and aggregate the replies from sub-messages.
A predefined Java Bean, AppendAggregator will be called to as the
strategy to aggregate the replies from sub-messages. For more information about creating
and using Java beans, see
Talend Studio User Guide.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package beans; import org.apache.camel.Exchange; import org.apache.camel.processor.aggregate.AggregationStrategy; public class AppendAggregator implements AggregationStrategy { public Exchange aggregate(Exchange oldEx, Exchange newEx) { if(oldEx==null){ return newEx; } String oldBody = oldEx.getIn().getBody(String.class); String newBody = newEx.getIn().getBody(String.class); newEx.getIn().setBody(oldBody + " " + newBody); return newEx; } } |
Dropping and linking the components
- From the Palette, expand the Custom folder. Drag and drop a cBeanRegister component onto the design workspace.
-
From the Orchestration folder, drag and drop a cTimer components onto the design
workspace. - From the Core folder, drag and drop two cSetBody and two cDirect components onto the design workspace.
-
From the Routing folder, drag and drop a
cSplitter component onto the design
workspace. -
From the Miscellaneous folder, drag and
drop two cLog components onto the design
workspace. -
Label the components to better identify their roles in the Route as shown
above. -
Right-click the cSplitter component,
select Row > Split from the contextual menu and click the cDirect component labeled
directA_sender. -
Right-click the cSplitter component
again, select Row > Route from the contextual menu and click the cLog component labeled
Log_Finished. -
In the same way, link the other components in the Route using the
Row > Route connection as shown above.
Configuring the components and connections
-
Double-click the cBeanRegister component
labeled appendAggregator to display its
Basic settings view in the Component tab. -
In the Id field, enter
"appendAggregator"
. Select the Simple option and in the Class
Name field, enter the name of the predefined Java bean,
beans.AppendAggregator
in this scenario, which will be
called later by the cSplitter
component. -
Double-click the cTimer component labeled
Starter to display its Basic settings view in the Component tab. -
In the Repeat field, enter
1
to trigger the message exchange. Keep the default settings of the other
options. -
Double-click the cSetbody component
labeled Set_body to display its Basic settings view in the Component tab. -
Select SIMPLE in the Language list and enter
"thing1, thing2,
in the Expression field
thing3"
as the message body. -
Configure the cSetbody component labeled
Set_new_body in the same way to set
new body to the sub-messages. In the Expression field, enter*** SPLIT: ${body}
to
add *** SPLIT: before the old message body. -
Double-click the cSplitter component to
display its Basic settings view in the
Component tab. -
In this use case, we want to split the message body into sub-messages
using,
as the separator.Select Simple in the Language list and enter${body}
in
the Expression field.Select the Use Strategy check box. In the
Strategy field, enter the Id of the
preregistered Java bean appendAggregator, which will be
used to aggregate the replies from sub-messages. -
Double-click the cDirect component
labeled directA_sender to display its
Basic settings view in the Component tab. -
Click […] and select the directA_receiver node to receive the
sub-messages. -
Double-click the cDirect component
labeled directA_receiver to display its
Basic settings view in the Component tab. -
In the Name field, type in
"directA"
to identify this endpoint. -
Keep the default settings of the cLog
components labeled Log_Finished and
Log_Split. Log_Finished will
log the aggregated replies from sub-messages. Log_Split
will log the sub-messages. - Press Ctrl+S to save your Route.
Viewing code and executing the Route
-
Click the Code tab at the bottom of the
design workspace to have a look at the generated code.As shown in the code, the message route is builtfrom
one
endpoint.to
another. The message sent to
cSplitter_1
is split by the method
.split().simple("${body}")
and the replies from the
sub-messages are aggregated by the method
.aggregationStrategyRef("appendAggregator")
. -
Click the Run view to display it and
click the Run button to launch the
execution of your Route. You can also press F6 to execute it.RESULT: The source message is split into sub-messages using,
as the separator and each sub-message is given a new message body. The
replies from the sub-messages are aggregated then into a single outgoing
message from the cSplitter
component.