Load balancing PDP Cluster using WSO2ESB

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
&lt;clustering class=&quot;org.apache.axis2.clustering.tribes.TribesClusteringAgent&quot;  enable=&quot;true&quot;&gt;
  • Configure the membership scheme used in this setup. We are using wka (Well-Known Address based multi-casting)
&lt;parameter name=&quot;membershipScheme&quot;&gt;wka&lt;/parameter&gt;
  • Configure the clustering domain/group.
&lt;parameter name=&quot;domain&quot;&gt;is.domain&lt;/parameter&gt;
  • Configure TCP port used by this member.
&lt;parameter name=&quot;localMemberPort&quot;&gt;4002&lt;/parameter&gt;
  • Configure The list of well-known members.. The well-known should be the WSO2 ESB server.
&lt;members&gt;
 &lt;member&gt;
 &lt;hostName&gt;127.0.0.1&lt;/hostName&gt;
 &lt;port&gt;4000&lt;/port&gt;
 &lt;/member&gt;
 &lt;/members&gt;

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
&lt;clustering  class=&quot;org.apache.axis2.clustering.tribes.TribesClusteringAgent&quot; enable=&quot;true&quot;&gt;
  • Configure the membership scheme used in this setup. We are using wka (Well-Known Address based multi-casting)
&lt;parameter name=&quot;membershipScheme&quot;&gt;wka&lt;/parameter&gt;
  • Configure the clustering domain/group. This must be differ from PDP cluster domain name.
&lt;parameter name=&quot;domain&quot;&gt;esb.domain&lt;/parameter&gt;
  • Configure IP address if this member and Configure TCP port used by this member.
&lt;parameter name=&quot;localMemberHost&quot;&gt;127.0.0.1&lt;/parameter&gt;

&lt;parameter name=&quot;localMemberPort&quot;&gt;4000&lt;/parameter&gt;
  • Configure The list of well-known members.. The well-known should be the WSO2 ESB server.
&lt;members&gt;
 &lt;member&gt;
 &lt;hostName&gt;127.0.0.1&lt;/hostName&gt;
 &lt;port&gt;4000&lt;/port&gt;
 &lt;/member&gt;
 &lt;/members&gt;
  • Enable group management for this node. Then application Domain must be the cluster domain name of the PDP cluster that we configured
&lt;groupManagement enable=&quot;true&quot;&gt;
 &lt;applicationDomain name=&quot;is.domain&quot;
 description=&quot;Axis2 group&quot;
 agent=&quot;org.apache.axis2.clustering.management.DefaultGroupManagementAgent&quot;/&gt;
 &lt;/groupManagement&gt;

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

&lt;proxy name=&quot;LoadBalancer&quot; transports=&quot;https http&quot; startOnLoad=&quot;true&quot; trace=&quot;disable&quot;&gt;
&lt;target&gt;
&lt;inSequence&gt;
&lt;log level=&quot;custom&quot;&gt;
&lt;property name=&quot;LOAD_BALANCER_INFO&quot; value=&quot;Message is received by Load Balancer&quot;/&gt;
&lt;/log&gt;
&lt;send&gt;
&lt;endpoint name=&quot;dynamicLB&quot;&gt;
&lt;session type=&quot;http&quot;/&gt;
&lt;dynamicLoadbalance algorithm=&quot;org.apache.synapse.endpoints.algorithms.RoundRobin&quot;&gt;
&lt;membershipHandler&gt;
&lt;property name=&quot;applicationDomain&quot; value=&quot;is.domain&quot;/&gt;
&lt;/membershipHandler&gt;
&lt;/dynamicLoadbalance&gt;
&lt;/endpoint&gt;
&lt;/send&gt;
&lt;/inSequence&gt;
&lt;outSequence&gt;
&lt;send/&gt;
&lt;/outSequence&gt;
&lt;/target&gt;
&lt;/proxy&gt;

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(&quot;http://destination.org&quot;));
options.setProperty(MessageContextConstants.TRANSPORT_URL, &quot;http://myProxy.org&quot;);
Discuss this article on Stack Overflow

Leave a Reply

Your email address will not be published. Required fields are marked *