We connect to a server fts.server using a web client using the below method .
webClient.post(config.getInteger("fts.port"), config.getString("fts.server"), config.getString("fts.indexpath")).putHeader(HttpHeaders.Names.AUTHORIZATION, "Basic " + base64key).sendJsonObject(jreq, ar -> {
if (ar.succeeded()) {
}
else
{
}
}
In my case i have fts.server1 , fts.server2 , fts.server3 all providing the same service . I need to load balance the calls between the servers and if any of them are off line try the other server . Some thing like
webClient.post(config.getInteger("fts.port"), (config.getString("fts.server1")) or config.getString("fts.server2")) or config.getString("fts.server3")) , config.getString("fts.indexpath")).putHeader(HttpHeaders.Names.AUTHORIZATION, "Basic " + base64key).sendJsonObject(jreq, ar -> {
if (ar.succeeded()) {
}
else
{
}
}
How do i do it ?
First, there are loadbalancers, specifically for that.
But to the point at hand. Instead of having one client and trying to loadbalance it, create N clients, and loadbalance between them.
Using Java9:
Now it's up to you to decide how do you loadbalance between them.
Random?
Round robin?
That's up to you.