In my previous blog post, I explained how we can configure PDP cluster load balancing with WSO2LB.
Lets see how we can configure WSO2ESB as load balancer for clustered PDPs. For that, we are using dynamic load balancing in ESB with session affinity. you can find the dynamic load balancing sample from here in WSO2 ESB docs.
1. Enable axis2 clustering in PDP nodes.
I assume you have already set a PDP cluster according to this blog post. Then we need to enable the axis2 level clustering among IS nodes to work with dynamic load balancer in ESB.
It is recommended to follow following article to get more knowledge and details on for Axis2 Clustering
http://wso2.org/library/articles/introduction-wso2-carbon-clustering
http://wso2.org/library/articles/wso2-carbon-cluster-configuration-language
Please configure following parameters in axis2.xml which can be found in <IS_HOME>/repository/conf directory
- Enable clustering
<clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true">
- Configure the membership scheme used in this setup. We are using wka (Well-Known Address based multi-casting)
<parameter name="membershipScheme">wka</parameter>
- Configure the clustering domain/group.
<parameter name="domain">is.domain</parameter>
- Configure TCP port used by this member.
<parameter name="localMemberPort">4002</parameter>
- Configure The list of well-known members.. The well-known should be the WSO2 ESB server.
<members> <member> <hostName>127.0.0.1</hostName> <port>4000</port> </member> </members>
You need configure axis2.xml in all PDP nodes.. Please note clustering domain and well-known member configurations must be same in all nodes
2. Enable axis2 clustering in Load Balancer (WSO2 ESB)
- Enable clustering
<clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true">
- Configure the membership scheme used in this setup. We are using wka (Well-Known Address based multi-casting)
<parameter name="membershipScheme">wka</parameter>
- Configure the clustering domain/group. This must be differ from PDP cluster domain name.
<parameter name="domain">esb.domain</parameter>
- Configure IP address if this member and Configure TCP port used by this member.
<parameter name="localMemberHost">127.0.0.1</parameter> <parameter name="localMemberPort">4000</parameter>
- Configure The list of well-known members.. The well-known should be the WSO2 ESB server.
<members> <member> <hostName>127.0.0.1</hostName> <port>4000</port> </member> </members>
- Enable group management for this node. Then application Domain must be the cluster domain name of the PDP cluster that we configured
<groupManagement enable="true"> <applicationDomain name="is.domain" description="Axis2 group" agent="org.apache.axis2.clustering.management.DefaultGroupManagementAgent"/> </groupManagement>
3. Creating Load balancer proxy service
we can create a proxy service in WSO2 ESB that could be acted as the load balancer. you can use following sample synapse configuration to
create the proxy. Here we have enable HTTP session affinity based on JSESSSIONID.
Please make sure that “applicationDomain” property value is the cluster domain name of the PDP cluster that we configured
<proxy name="LoadBalancer" transports="https http" startOnLoad="true" trace="disable"> <target> <inSequence> <log level="custom"> <property name="LOAD_BALANCER_INFO" value="Message is received by Load Balancer"/> </log> <send> <endpoint name="dynamicLB"> <session type="http"/> <dynamicLoadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin"> <membershipHandler> <property name="applicationDomain" value="is.domain"/> </membershipHandler> </dynamicLoadbalance> </endpoint> </send> </inSequence> <outSequence> <send/> </outSequence> </target> </proxy>
Then your authorization services (Entitlement Service) of each PDP nodes has been exposed by a single access point. Which would be as following according this sample config
http://{WSO2ESB IP}:{WSO2ESB PORT}/services/LoadBalancer
Here PEP wants to send your message through a proxy service before it reaches to its destination. This means you want to give transport URL different from the URL of the ultimate destination. As an example, If Axis2 client is used, you can set this as following (you would need to engage the addressing module also)
opts.setTo(new EndpointReference("http://destination.org")); options.setProperty(MessageContextConstants.TRANSPORT_URL, "http://myProxy.org");