public List <string> FindServiceEndpoints(bool filterBlack = true) { if (_client == null) { throw new ArgumentNullException("consul client"); } var targets = new List <string>(); try { var r = _client.Health.Service(ServiceName, "", true).Result; if (r.StatusCode != HttpStatusCode.OK) { throw new ApplicationException($"failed to query consul server"); } targets = r.Response .Select(x => $"{x.Service.Address}:{x.Service.Port}") .Where(x => !ServiceBlackPlicy.In(x) || !filterBlack) .ToList(); //var res = _client.Catalog.Service(ServiceName).Result; //if (res.StatusCode != HttpStatusCode.OK) // throw new ApplicationException($"Failed to query services"); //targets = res.Response // .Select(x => $"{x.ServiceAddress}:{x.ServicePort}") // .Where(x => !ServiceBlackPlicy.In(x) || !filterBlack) // .ToList(); //return targets; } catch { } return(targets); }
public List <string> FindServiceEndpoints(bool filterBlack = true) { if ((_ipEndPoints?.Count ?? 0) <= 0) { throw new ArgumentOutOfRangeException("endpoint not provide"); } var targets = _ipEndPoints.Select(x => $"{x.Item1}:{x.Item2}") .Where(x => !ServiceBlackPlicy.In(x) || !filterBlack) .ToList(); return(targets); }