Skip to content

Session Affinity Load Balancing between Three Endpoints

This sample demonstrates how the Micro Integrator can handle load balancing with session affinity using simple client sessions. Here the session type is specified as simpleClientSession . This is a client initiated session, which means that the client generates the session identifier and sends it with each request. In this sample session type, the client adds a SOAP header named ClientID containing the identifier of the client. The MI binds this ID with a server on the first request and sends all successive requests containing that ID to the same server.

Synapse configuration

Following is a sample REST API configuration that we can used to implement this scenario.

<proxy name="LoadBalanceProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
   <target>
       <inSequence>
            <header name="Action" value="urn:placeOrder"/>
            <call>
                <endpoint>
                    <!-- specify the session as the simple client session provided by Synapse for
                    testing purpose -->
                    <session type="simpleClientSession"/>

                    <loadbalance>
                        <endpoint>
                            <address uri="http://localhost:9001/services/LBService1">
                                <enableAddressing/>
                            </address>
                        </endpoint>
                        <endpoint>
                            <address uri="http://localhost:9002/services/LBService1">
                                <enableAddressing/>
                            </address>
                        </endpoint>
                        <endpoint>
                            <address uri="http://localhost:9003/services/LBService1">
                                <enableAddressing/>
                            </address>
                        </endpoint>
                    </loadbalance>
                </endpoint>
            </call>
            <respond/>
       </inSequence>
       <outSequence>
            <send/>
       </outSequence>
       <faultSequence>
            <sequence key="errorHandler"/>
       </faultSequence
   </target>
</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>
Top