This documentation is for WSO2 Enterprise Service Bus version 4.8.1 . View documentation for the latest release.

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

Objective: Demonstrate how to use endpoint templates in a load balance configuration.

<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 name="templ_ep1" template="endpoint_template" uri="http://localhost:9001/services/LBService1">
				<parameter name="suspend_duration" value="5"/>
                            </endpoint>
			    <endpoint name="templ_ep2" template="endpoint_template" uri="http://localhost:9002/services/LBService1">
				<parameter name="suspend_duration" value="20"/>
                            </endpoint>
			    <endpoint name="templ_ep3" template="endpoint_template" uri="http://localhost:9003/services/LBService1">
				<parameter name="suspend_duration" value="200"/>
                            </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>
        <send/>
    </sequence>



    <template name="endpoint_template">
	    <parameter name="suspend_duration"/>
	    <endpoint name="annonymous">
		<address uri="$uri">
		    <enableAddressing/>
                    <suspendDurationOnFailure>$suspend_duration</suspendDurationOnFailure>
		</address>
	    </endpoint>
    </template>

</definitions>

Prerequisites:

  • Sample setup is same as LoadBalance endpoint scenario (#154).
  • Start the Synapse configuration numbered 752: i.e. wso2esb-samples -sn 752
  • Start the Axis2 server and deploy the LoadbalanceFailoverService if not already done

Configuration demonstrates a single endpoint template named 'endpoint_template'. Three endpoint templates are created inside loadbalance endpoint which will point to this template. Note different parameters passed on to the same template ie:- service url and suspend duration as parameters

Invoke the client as follows.

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

As in the previous loadbalance samples client console will show loadbalance requests going towards three endpoints created from the same template. Notice differnt suspension times for three services in a failed endpoint scenario as well. (reflects different parameters passed onto the template).

  • No labels