Thursday, September 3, 2015

How to send request in multiple endpoints in WSO2 ESB

If there is a scenario in which we have to send a request to multiple endpoints then this can be achieved by the Recipient List Endpoints. It can contain multiple child endpoints in which we have send request.  It routes cloned copies of messages to each child recipient.

Syntax:

<recipientlist>
    <endpoint .../>+
</recipientlist>

As illustrated below diagram an incoming message is transferred to any number of endpoint defined inside of <recipientlist> tag.  



Example:

In below example we are trying to send same message to three different endpoints which have been defined inside of send mediator.

<!-- Start of GetEmployeeDetailsProxy-->
<proxy name="GetEmployeeDetailsProxy" transports="https http" startOnLoad="true" trace="disable" statistics="enable">
<target inSequence="GetEmployeeDetailsProxy_IN" outSequence="GetEmployeeDetailsProxy_OUT" faultSequence="CommonFaultHandler"/>
<publishWSDL key="GetEmployeeDetailsProxy_wsdl"/>
</proxy>
<localEntry key="GetEmployeeDetailsProxy_wsdl" src="file:repository/conf/employee/resources/proxy/employeeDetails.wsdl"/>
<sequence name="GetEmployeeDetailsProxy_IN">
<log level="full"/>
<script language="js">java.lang.Thread.sleep(25000);</script>
<send>
<!--Dynamic Recipient List-->
<endpoint>
<recipientlist>
<endpoint>
<address uri="http://xxxx1:8280/services/GetEmployeeDetailsProxy"/>
</endpoint>
<endpoint>
<address uri="http://xxxx2:8280/services/GetEmployeeDetailsProxy"/>
</endpoint>
<endpoint>
<address uri="http://xxxx3:8280/services/GetEmployeeDetailsProxy"/>
</endpoint>
</recipientlist>
</endpoint>         
</send>
</sequence>
<sequence name="GetEmployeeDetailsProxy_OUT">
<log level="full"/>
<send/>
</sequence>
<!-- End of GetEmployeeDetailsProxy-->

There are 3 endpoint defined and request will send to each endpoint. Endpoint can be increased as required, just need to add endpoint entry in synapse.