Sample 400: Message Splitting and Aggregation

<definitions xmlns=""> <proxy name="SplitAggregateProxy"> <target> <inSequence> <iterate xmlns:m0="http://services.samples" expression="//m0:getQuote/m0:request" preservePayload="true" attachPath="//m0:getQuote"> <target> <sequence> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </sequence> </target> </iterate> </inSequence> <outSequence> <aggregate> <onComplete xmlns:m0="http://services.samples" expression="//m0:getQuoteResponse"> <send/> </onComplete> </aggregate> </outSequence> </target> </proxy> </definitions>


Showcase how Synapse can be used to split a message into multiple fragments using the iterate mediator, and process them separately. The sample also shows how to use the aggregate mediator to combine multiple messages into one.


  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 400 (repository/conf/sample/synapse_sample_400.xml)
    Unix/Linux: sh -sample 400
    Windows: synapse.bat -sample 400

Executing the Client

In this sample, the message sent to Synapse is comprised of a number of elements of the same type. When Synapse receives this message it will iterate through those elements and then will send each of them to the specified endpoint as separate messages. When all the responses are received by Synapse, those messages will be aggregated to form the resultant response and will send back to the client.

To try this out invoke the sample client as follows.

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

The above command will send a request containing four fragments in it. The iterate mediator therefore will break up the message into four. You will notice that Axis2 server is receiving 4 requests from Synapse. Four responses from Axis2 will be combined into one by the aggregate mediator and sent back to the sample Axis2 client.

Back to Catalog