<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one
  ~  or more contributor license agreements.  See the NOTICE file
  ~  distributed with this work for additional information
  ~  regarding copyright ownership.  The ASF licenses this file
  ~  to you under the Apache License, Version 2.0 (the
  ~  "License"); you may not use this file except in compliance
  ~  with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<document>
    <properties>
        <title>Apache Synapse - Sample 154</title>
    </properties>
    <body>
        <section name="Sample 154: Load Balancing with Proxy Services">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;proxy name="LBProxy" transports="http" startOnLoad="true"&gt;
        &lt;target faultSequence="errorHandler"&gt;
            &lt;inSequence&gt;
                &lt;send&gt;
                    &lt;endpoint&gt;
                        &lt;session type="simpleClientSession"/&gt;
                        &lt;loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin"&gt;
                            &lt;endpoint&gt;
                                &lt;address uri="http://localhost:9001/services/LBService1"&gt;
                                    &lt;enableAddressing/&gt;
                                    &lt;suspendDurationOnFailure&gt;20&lt;/suspendDurationOnFailure&gt;
                                &lt;/address&gt;
                            &lt;/endpoint&gt;
                            &lt;endpoint&gt;
                                &lt;address uri="http://localhost:9002/services/LBService1"&gt;
                                    &lt;enableAddressing/&gt;
                                    &lt;suspendDurationOnFailure&gt;20&lt;/suspendDurationOnFailure&gt;
                                &lt;/address&gt;
                            &lt;/endpoint&gt;
                            &lt;endpoint&gt;
                                &lt;address uri="http://localhost:9003/services/LBService1"&gt;
                                    &lt;enableAddressing/&gt;
                                    &lt;suspendDurationOnFailure&gt;20&lt;/suspendDurationOnFailure&gt;
                                &lt;/address&gt;
                            &lt;/endpoint&gt;
                        &lt;/loadbalance&gt;
                    &lt;/endpoint&gt;
                &lt;/send&gt;
                &lt;drop/&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_2.wsdl"/&gt;
    &lt;/proxy&gt;

    &lt;sequence name="errorHandler"&gt;
        &lt;makefault response="true"&gt;
            &lt;code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/&gt;
            &lt;reason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
                    Demonstrate how to use a proxy service as a load balancer
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Deploy the LoadbalanceFailoverService in the sample Axis2 server (go to
                            samples/axis2Server/src/LoadbalanceFailoverService and run 'ant')
                        </li>
                        <li>
                            Start 3 instances of the Axis2 server on different ports as follows
                            <div class="command">./axis2server.sh -http 9001 -https 9005 -name MyServer1<br/>
./axis2server.sh -http 9002 -https 9006 -name MyServer2<br/>
./axis2server.sh -http 9003 -https 9007 -name MyServer3</div>
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 154 (repository/conf/sample/synapse_sample_154.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 154<br/>
                                Windows: synapse.bat -sample 154
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    This sample is similar to <a href="sample54.html">sample 54</a>. The only
                    notable difference is the use of a proxy service.
                </p>
                <p>
                    Execute the client as follows.
                </p>
                <div class="command">ant loadbalancefailover -Dmode=session -Dtrpurl=http://localhost:8280/services/LBProxy</div>
                <p>
                    You will get an output similar to the following.
                </p>
                <div class="consoleOutput">[java] Request: 1 Session number: 1 Response from server: MyServer3
[java] Request: 2 Session number: 2 Response from server: MyServer2
[java] Request: 3 Session number: 0 Response from server: MyServer1
[java] Request: 4 Session number: 2 Response from server: MyServer2
[java] Request: 5 Session number: 1 Response from server: MyServer3
[java] Request: 6 Session number: 2 Response from server: MyServer2
[java] Request: 7 Session number: 2 Response from server: MyServer2
[java] Request: 8 Session number: 1 Response from server: MyServer3
[java] Request: 9 Session number: 0 Response from server: MyServer1
[java] Request: 10 Session number: 0 Response from server: MyServer1
... </div>
                <p>
                    You can see that session ID 0 is always directed to the server named MyServer1.
                    That means session ID 0 is bound to MyServer1. Similarly session 1 and 2 are bound
                    to MyServer3 and MyServer2 respectively.
                </p>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>