## Apache Synapse

## Sample 853: Introduction to Synapse Scatter-Gather eip function template

<definitions xmlns="http://ws.apache.org/ns/synapse"> <import xmlns="http://ws.apache.org/ns/synapse" name="EipLibrary" package="synapse.lang.eip" /> <sequence name="enr"> <log level="custom"> <property name="text" value="seqhit"/> </log> <enrich> <source xmlns:m0="http://services.samples" clone="true" xpath="//m0:return[not(preceding-sibling::m0:return/m0:last &lt;= m0:last) and not(following-sibling::m0:return/m0:last &lt; m0:last)]"/> <target type="body"/> </enrich> <send/> </sequence> <sequence name="main"> <call-template target="synapse.lang.eip.scatter_gather"> <with-param name="sequence_ref" value="enr"/> <with-param xmlns:m0="http://services.samples" name="aggregator_exp" value="{{//m0:return}}"/> <with-param name="oncomplete_seq_enabled" value="true"/> <with-param name="recipient_list" value="http://localhost:9001/services/SimpleStockQuoteService,http://localhost:9002/services/SimpleStockQuoteService,http://localhost:9003/services/SimpleStockQuoteService"/> </call-template> </sequence> </definitions>

### Objective

This sample is an introduction to Synapse Scatter-Gather eip function template. Scatter-Gather pattern broadcasts a message to multiple recipients and re-aggregates the responses back into a single message and send back to client or mediates to the defined target sequence.

### Pre-requisites

- Start three instances of sample Axis2 server on HTTP ports 9001,9002,9003. And deploy the SimpleStockQuoteService in all of them.
- Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
- Start Synapse using the configuration numbered 853 (repository/conf/sample/synapse_sample_853.xml)
  Unix/Linux: sh synapse.sh -sample 853
  Windows: synapse.bat -sample 853

### Executing the Client

In this sample, the message sent to Synapse will be broadcast to the specified recipients. Then aggregates replies and mediates to the defined target sequence which filter the response which contains the best quote and send back to the client.

Invoke the client as follows.

ant stockquote -Dtrpurl=http://localhost:8280/

Back to Catalog