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.
Interesting Question & Requirement,
I think you can solve above issue using Proxy Chaining concept. See below steps to achieve same.
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.
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.
@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.
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.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |