This sample demonstrates how the ESB can handle load balancing with session affinity using simple client sessions. The configuration used here is the same as the configuration in sample 52, except that 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 ESB binds this ID with a server on the first request and sends all successive requests containing that ID to the same server.
For a list of prerequisites, see Prerequisites to Start the ESB Samples.
Building the sample
The XML configuration for this sample is as follows:
This configuration file
synapse_sample_54.xml is available in the
To build the sample
Start the ESB with the sample 54 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."
Start three instances of the sample Axis2 server on HTTP ports 9001, 9002 and 9003 and give unique names to each server. For instructions on starting the Axis2 server, see Starting the Axis2 server.
Deploy the back-end service
LoadbalanceFailoverService. For instructions on deploying sample back-end services, see Deploying sample back-end services.
Executing the sample
The sample client used here is the Load Balance and Failover Client.
To execute the sample client
Run the following command from the
Analyzing the output
When the client is run in the session mode, the client continuously sends requests with three different session IDs. Out of these three IDs one ID is selected randomly for each request. Then the client prints the session ID with the server that responds for each request.
When you analyze the output on the client console, you will see the client output for the first 10 requests, which will be as follows:
By analysing the above output, you will see that the session number 0 is always directed to the server named MyServer1. This means that the session number 0 is bound to MyServer1. Similarly, session 1 s always directed to MyServer3 and session 2 is always directed to MyServer2. This means that session 1 and 2 are bound to MyServer3 and MyServer2 respectively.