| <?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 54</title> |
| </properties> |
| <body> |
| <section name="Sample 54: Session Affinity Load Balancing Between 3 Endpoints"> |
| <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse"> |
| |
| <sequence name="main" onError="errorHandler"> |
| <in> |
| <send> |
| <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> |
| </send> |
| <drop/> |
| </in> |
| |
| <out> |
| <!-- Send the messages where they have been sent (i.e. implicit To EPR) --> |
| <send/> |
| </out> |
| </sequence> |
| |
| <sequence name="errorHandler"> |
| <makefault response="true"> |
| <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/> |
| <reason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/> |
| </makefault> |
| <send/> |
| </sequence> |
| |
| </definitions></div> |
| <subsection name="Objective"> |
| <p> |
| Showcase the ability of Synapse to act as a session aware load balancer with |
| simple client sessions |
| </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 54 (repository/conf/sample/synapse_sample_54.xml) |
| <div class="command"> |
| Unix/Linux: sh synapse.sh -sample 54<br/> |
| Windows: synapse.bat -sample 54 |
| </div> |
| </li> |
| </ul> |
| </p> |
| </subsection> |
| <subsection name="Executing the Client"> |
| <p> |
| Above configuration is same as the load balancing configuration in |
| <a href="sample52.html">sample 52</a>, except that 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, client adds a SOAP header named ClientID containing the identifier |
| of the client. Synapse binds this ID with a server on the first request and sends |
| all successive requests containing that ID to the same server. Now switch to |
| samples/axis2Client directory and run the client using the following command to |
| check this in action. |
| </p> |
| <div class="command">ant loadbalancefailover -Dmode=session</div> |
| <p> |
| In the session mode, client continuously sends requests with three different |
| client (session) IDs. One ID is selected among these three IDs for each request |
| randomly. Then client prints the session ID with the responded server for each |
| request. Client output for the first 10 requests are shown below. |
| </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> |