Objective: Demonstrate the simple dynamic load balancing among a set of nodes
Enable clustering and group management in the <ESB installation directory>/ repository/conf/axis2.xml file. This can be done by setting the "enable" attribute of the "cluster" and "groupManagement" elements. Also provide the IP address of you machine as the values of the "mcastBindAddress" and "localMemberHost" parameters.
Start ESB with sample configuration 57: i.e.
wso2esb-samples.sh -sn 57
LoadbalanceFailoverService by switching to
<Synapse installation directory>/samples/axis2Server/src/LoadbalanceFailoverService directory and running ant.
Enable clustering in the <Synapse installation directory>/samples/axis2Server/ repository/conf/axis2.xml file. This can be done by setting the "enable" attribute of the "cluster" element. Also provide the IP address of you machine as the values of the "mcastBindAddress" and "localMemberHost" parameters. Make sure that the "applicationDomain" of the membershipHandler is the same as the domain name specified in the axis2.xml files of the Axis2 servers. Then Start three instances of sample Axis2 server on HTTP ports 9001, 9002 and 9003 and give some unique names to each server.
Example commands to run sample Axis2 servers from the
<Synapse installation directory>/samples/axis2Server directory in Linux are listed below:
Now we are done with setting up the environment for load balance sample. Start the load balance and failover client using the following command:
This client sends 100 requests to the LoadbalanceFailoverService through Synapse. Synapse will distribute the load among the three nodes mentioned in the configuration in a round-robin manner. LoadbalanceFailoverService appends the name of the server to the response, so that client can determine which server has processed the message. If you examine the console output of the client, you can see that requests are processed by three servers as follows:
Now run the client without the -Di=100 parameter, i.e. ant loadbalancefailover, to send infinite requests. While running the client shutdown the server named MyServer1. You can observe that requests are only distributed among MyServer2 and MyServer3 after shutting down MyServer1. Console output before and after shutting down MyServer1 is listed below (MyServer1 was shutdown after request 63):
Now restart MyServer1. You can observe that requests will be again sent to all three servers.