This documentation is for WSO2 ESB version 4.5.0. View documentation for the latest release.

Sample 154: Load Balancing with Proxy Services

Objective: Load Balancing with Proxy Service.

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="LBProxy" transports="https http" startOnLoad="true">
        <target faultSequence="errorHandler">
            <inSequence>
                <send>
                    <endpoint>
                        <session type="simpleClientSession"/>
                        <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
                            <endpoint>
                                <address uri="http://localhost:9001/services/LBService1">
                                    <enableAddressing/>
                                    <suspendDurationOnFailure>20</suspendDurationOnFailure>
                                </address>
                            </endpoint>
                            <endpoint>
                                <address uri="http://localhost:9002/services/LBService1">
                                    <enableAddressing/>
                                    <suspendDurationOnFailure>20</suspendDurationOnFailure>
                                </address>
                            </endpoint>
                            <endpoint>
                                <address uri="http://localhost:9003/services/LBService1">
                                    <enableAddressing/>
                                    <suspendDurationOnFailure>20</suspendDurationOnFailure>
                                </address>
                            </endpoint>
                        </loadbalance>
                    </endpoint>
                </send>
                <drop/>
            </inSequence>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_2.wsdl"/>
    </proxy>
    <sequence name="errorHandler">
        <makefault>
            <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>
            <reason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/>
        </makefault>
        <header name="To" action="remove"/>
        <property name="RESPONSE" value="true"/>
        <send/>
    </sequence>
</definitions>
Prerequisites
  • Start the Synapse configuration numbered 154: i.e. wso2esb-samples.sh -sn 154
  • Start the Axis2 server and deploy the SecureStockQuoteService if not already done.

Run the client with

ant loadbalancefailover -Dmode=session -Dtrpurl=http://localhost:8280/services/LBProxy