OSB has a built-in support for load balancing as business services in OSB allows multiple end points to be added that can be load balanced using predefined load-balancing algorithm.
The load balancing will be achieved by creating two business services:
• Business Service A — This will be a real business service which will accept an input and will reply with some output.
• Business Service B — This will be a pass-through service which will not give any response.
A proxy service will be created later which will load balance between these two business services. Based on the load-balancing algorithm, one of the business service will be called. For e.g., if it is a round-robin algorithm — for the first invocation of proxy service, it will call Business Service A and for the subsequent invocation it will call the Business Service B.
As discussed earlier, we will create two business services first, then a proxy to call them in load-balancing algorithm. The assumption is that user has the basic knowledge of OSB.
1. Create Business Services
Log in to OSB console using the following URL:
http://host:port/sbconsole
Once you are logged in to OSB console, create an OSB session.
After the session is created, go to project explorer and create a new folder for your project.
The business service we are going to use in our implementation is following:
http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?WSDL
Create a Web Service Description Language (WSDL) resource in your project.
Specify it a unique name and paste the content of the WSDL mentioned in the high-level solution.
Save the changes for the WSDL and create a business service based on the above WSDL as shown below:
Select CalculatorSoap port and complete the wizard.
The actual end-point location of the calculator Web service gets added in the list.
It uses a round robin load-balancing algorithm by default.
2. Add service for load balancing
Click on add and you will find that one more address in added in the existing URLs list.
Now, here the second URL that we have added is not an actual Web service, it is a dummy end-point URL added by the wizard itself. (This is the second dummy service which we will use in this case to be load balanced.)
As per the current configuration, it says that we now have two end-point URL’s in the business service which are load balanced internally using a round-robin algorithm.
You can change the algorithm based on your requirement, keep the default format for testing.
Complete the wizard
Save the change and activate your OSB session.
3. Create Proxy Service
Create a wrapper OSB proxy service to call this business service.
Go to your project explorer.
Create a proxy service from the resource wizard and just call the business service you have created now.
Complete the configuration. Save the configuration and activate the changes.
This is the proxy service which will call the two business services in a load balancer.
4. Test the configuration
Test the proxy service.
Test the proxy service with the default input.
You will get two sets of output when two consecutive tests are performed.
One will fetch you a correct result and other will say the business service does not exist.
This happens because internally the two end-point URL’s specified in the business service are load balanced using round-robin algorithm, which means the services will be called on a round robin fashion, i.e., if first call fails (calling the dummy end point), the second call will succeed.
Below is the output for a consecutive call to the proxy service.
As discussed in the log balancing algorithm, the load balancer moves from one service to another as per the algorithm. In this scenario, it was round-robin algorithm, hence the proxy service first called the business service that is developed and then it called the dummy end point URL.