public async Task <ServiceAgent> GetAsync(string name) { var services = await _consulService.GetServiceAgentsAsync(name); if (!services.Any()) { return(null); } if (!_usedServices.ContainsKey(name)) { _usedServices[name] = new HashSet <string>(); } else if (services.Count == _usedServices[name].Count) { _usedServices[name].Clear(); } return(GetService(services, name)); }
public async Task <ServiceAgent> GetAsync(string name) { //give me a instance of service from available instances (pick first from unused instance) 'client side load balancing' or some sort of work like load balancing var services = await _consulService.GetServiceAgentsAsync(name); if (!services.Any()) { return(null); } if (!_usedServices.ContainsKey(name)) { _usedServices[name] = new HashSet <string>(); } else if (services.Count == _usedServices[name].Count) { _usedServices[name].Clear(); } return(GetService(services, name)); }