public bool CanAcceptCalls() { if (!TryGetHealthClient(out Health.HealthClient healthClient)) { return(false); } string serviceName = ChannelServiceName; bool result = GrpcUtils.IsServing(healthClient, serviceName, out StatusCode statusCode); _msg.DebugFormat("Service {0} is serving at {1}: {2}. Status: {3}", serviceName, Channel?.ResolvedTarget, result, statusCode); return(result); }
private static bool IsServingLoadBalancerEndpoint( [NotNull] Channel channel, [NotNull] ChannelCredentials credentials, string serviceName, int enoughForLargeGeometries) { var channelHealth = new Health.HealthClient(channel); bool isServingEndpoint = GrpcUtils.IsServing(channelHealth, serviceName, out _); if (isServingEndpoint) { return(false); } bool isLoadBalancer = GrpcUtils.IsServing(channelHealth, nameof(ServiceDiscoveryGrpc), out StatusCode lbStatusCode); if (isLoadBalancer) { _msg.DebugFormat("{0} is a load balancer address.", channel.ResolvedTarget); Channel suggestedLocation = TryGetChannelFromLoadBalancer(channel, credentials, serviceName, enoughForLargeGeometries); if (suggestedLocation != null) { _msg.DebugFormat("Using serving load balancer at {0}", channel.ResolvedTarget); return(true); } // Assumption: A load balancer is never also serving real requests -> lets not use it at all! _msg.Debug( "The load balancer has no service locations available. It will not be used."); return(false); } _msg.DebugFormat("No {0} service and no serving load balancer at {1}. Error code: {2}", serviceName, channel.ResolvedTarget, lbStatusCode); return(false); }