How to update load balance ?
MrSpark2591 opened this issue · 3 comments
I am trying to update load balance for this code. here i have loadBalancing map which is something like :
loadBalancingMap = { serviceName : [url1,url2] }
and i am using it o register service and balancer like this :
proxy .all('/'.concat(serviceName).concat('/*')) .balance(loadBalancingMap[serviceName])
now how can i update balance for this service when there is one more instance of service or some instance failed.
You can simply call .balance()
method again.
@h2non yes, I thought that and tried. this is what I have done.here what I am doing is reassigning the whole thing by calling this function whenever my 'loadBalancingMap' value change. can you tell me what I am doing wrong? I know it's just silly thing but I am really not getting how to overcome.
var regeisterProxyRoute = function(serviceName){
proxy
.all('/'.concat(serviceName).concat('/*'))
.balance(loadBalancingMap[serviceName])
};
You have to store the route object reference you're implicitly creating via: proxy.all('/'.concat(serviceName).concat('/*'))
.
So your code might look like:
var routes = {}
var registerProxyRoute = function (serviceName) {
const path = '/'.concat(serviceName).concat('/*')
const route = routes[path] = routes[path] || proxy.all(path)
route.balance(loadBalancingMap[serviceName])
}