This documentation is for WSO2 Enterprise Service Bus version 5.0.0. For the latest ESB, view the latest WSO2 Enterprise Integrator documentation.

All docs This doc
Skip to end of metadata
Go to start of metadata

Objective: Demonstrate the use of templates in Split/Aggregate scenario.

<definitions xmlns="">

    <proxy name="SplitAggregateProxy">
		<!--use iterate sequence template to split incoming request and send-->
                <call-template target="iter_func">
                        <with-param xmlns:m0="http://services.samples" name="iter_expr" value="{{//m0:getQuote/m0:request}}"/>
 			<with-param xmlns:m0="http://services.samples" name="attach_path" value="{{//m0:getQuote}}"/>
		<!--use aggregate sequence template to combine the responses and send back-->
                <call-template target="aggr_func">
                        <with-param xmlns:m0="http://services.samples" name="aggr_expr" value="{{//m0:getQuoteResponse}}"/>

    <!--this sequence template will aggregate the responses , merge and send back to the client. This takes aggregate
	expression as an argument-->
    <template xmlns="" name="aggr_func">
        <parameter name="aggr_expr"/>
            <log level="full"/>
                    <messageCount min="-1" max="-1"/>
                <onComplete expression="$func:aggr_expr">
                    <log level="full" />

    <!--this sequence template will iterate through stock quote symbols ,split and send them to endpoints. Takes Iterate
	expression and soap attaach path as arguments -->
    <template xmlns="" name="iter_func">
        <parameter name="iter_expr"/>
        <parameter name="attach_path"/>

            <iterate  xmlns:m0="http://services.samples" preservePayload="true" attachPath="$func:attach_path" expression="$func:iter_expr">
                                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>


  • Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.
  • Start ESB with the sample configuration 751 (i.e. wso2esb-samples -sn 751).

This will be the same sample demonstrated in advanced mediation with Iterate mediator used to split the messages in to parts and process them asynchronously and then aggregate the responses coming in to ESB. Only addition will be two sequence templates 'iter_func' and 'aggr_func' which will split the message and aggregate the responses back , respectively.

Invoke the client as follows.

ant stockquote -Daddurl=http://localhost:8280/services/SplitAggregateProxy -Ditr=4

Sequence Template 'iter_func' takes iterate expressions and attach path as arguments. Sequence Template 'aggr_func' takes aggregate expression as argument.

In this sample we are using special dynamic xpath expressions(in double curly braces {{expr}}) in call-template mediator so that they are evaluated only when iteration and aggregation is done. Note that function scope (ie:-$func) is used to access template parameters in 'iter_func' and 'aggr_func'.

  • No labels