Load balancing through javascript callout

Not applicable

Hi All,

I have to call a HTTP service asynchronously from a Java script. I am able to call but dont know how to implement load balancing.

Following is my Javascript:

var myRequest = new Request();

myRequest.url = "http://abc.com/audit/v1"; //(It works with this)

//myRequest.url = "http://xyz.com/audit/v1";(this also has to be added as load balancing URL)

myRequest.method = "POST";

//< build myRequest body here>

var exchangeObj = httpClient.send(myRequest);

Anybody has any idea how to implement the same?

Thanks in advance.

2 3 146
3 REPLIES 3

@Alok Kumar Singh ,

Interesting Question & Requirement,

I think you can solve above issue using Proxy Chaining concept. See below steps to achieve same.

  • Create a new pass through proxy which implements load balancing across multiple target servers in Apigee which load balances across abc.com & xyz.com
  • Call above proxy in your original proxy using service callout instead of javascript policy.

Also, I don't think javascript callout has any support out of the box for load balancing. You can write a simple logic where you can load balance based on probability. For Example,

if (Math.random() > 0.5) {
myRequest.url = "http://abc.com/audit/v1";
} else {
myRequest.url = "http://xyz.com/audit/v1";
}

Hope it helps.

@Anil Sagar

I think service callout would have served the purpose but in documentation i saw the async attribute is deprecated for service callout. I have a requirement where this call should be asynchronous hence looking for javascript callout.

3192-capture.png

@Alok Kumar Singh , Async attribute neither execute policy asynchronously nor it calls service callout api asynchronously.

Regarding, calling API asynchronously , I am sure you have referred this article already.

  • You need to use the method mentioned in the article to make async http call.
  • Remember, above method works fine if you are not worried above response from async http call.
  • It also works if you are looking for response from async http call, as long as you delay the API Proxy execution & keep checking whether async call response is available to process.

I have already answered your query on how to do load balancing & i hope above points helps you to get clarification regarding async http calls.