Alex
Alex

Reputation: 1535

Writing a load balance algorithm for WSO2 ESB

I'm facing up to the load balance algorithm implementation for customizing the load balance endpoint.

On this documentation page: http://docs.wso2.org/display/ESB470/Load-balance+Endpoint

I read:

Algorithm - Either a default "Round-robin" or custom loaded algorithm of the group. See more information about this algorithm in the article.

Where "article" is a link point to this page:

http://supunk.blogspot.it/2010/02/writing-load-balance-algorithm-for-wso2.html

But the referred article is not complete and doesn't tell anything about the algorithm development. Could anyone give me a valid example?

Upvotes: 0

Views: 742

Answers (3)

Alex
Alex

Reputation: 1535

Looking at LoadBalanceAlgortihm it's not possibile to simply give it a dynamic list of endpoint. Concerning LoadBalanceMambershipHandler and its implementation (Axis2 and Service)...it uses object like:

org.apache.axis2.clustering.management.GroupManagementAgent
and
org.apache.axis2.clustering.ClusteringAgent

so you have to configure your nodes in cluster using the axi2.xml inside /repository/conf/axis2 folder of your ESB. Use the ESB registry to save the loadbalance enpoint in and then access it by code for adding it a new list of address endpoint.

Upvotes: 0

jayalalk
jayalalk

Reputation: 2496

You can use below sample to send multiple request to share between diffent endpoint using RoundRobin algo.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TestLoadBalance"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <endpoint>
         <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService/"/>
            </endpoint>
            <endpoint>
               <address uri="http://localhost:9001/services/SimpleStockQuoteService/"/>
            </endpoint>
            <endpoint>
               <address uri="http://localhost:9002/services/SimpleStockQuoteService/"/>
            </endpoint>
         </loadbalance>
      </endpoint>
   </target>
   <description/>
</proxy>

Upvotes: 2

Nufail
Nufail

Reputation: 1598

As the documentation specifies, the algorithm should be an implementation of org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm

You need to write a class implementing LoadbalanceAlgorithm interface. You can refer the existing implementations RoundRobin, WeightedRRLCAlgorithm and WeightedRoundRobin classes found in org.apache.synapse.endpoints.algorithms package.

Then create a jar file with your class and add it to <ESB_HOME>/repository/components/lib folder and restart the server.

Now when adding a Load Balance Endpoint, select Other... for the Algorithm and provide the full classname of your custom algorithm. For example: org.apache.synapse.endpoints.algorithms.WeightedRoundRobin

Upvotes: 0

Related Questions