Пример #1
0
        protected void OpenChannel(bool useTls,
                                   string clientCertificate = null,
                                   bool assumeLoadBalancer  = false)
        {
            if (string.IsNullOrEmpty(HostName))
            {
                _msg.Debug("Host name is null or empty. No channel opened.");
                return;
            }

            ChannelCredentials credentials =
                GrpcUtils.CreateChannelCredentials(useTls, clientCertificate);

            var enoughForLargeGeometries = (int)Math.Pow(1024, 3);

            Channel channel = GrpcUtils.CreateChannel(
                HostName, Port, credentials, enoughForLargeGeometries);

            if (assumeLoadBalancer)
            {
                ChannelIsLoadBalancer =
                    IsServingLoadBalancerEndpoint(channel, credentials, ServiceName,
                                                  enoughForLargeGeometries);
            }

            Channel = channel;

            _msg.DebugFormat("Created grpc channel to {0} on port {1}", HostName, Port);

            _healthClient = new Health.HealthClient(Channel);

            ChannelOpenedCore(Channel);
        }
Пример #2
0
        protected static Channel TryGetChannelFromLoadBalancer(Channel lbChannel,
                                                               ChannelCredentials credentials,
                                                               string serviceName,
                                                               int maxMesssageLength)
        {
            ServiceDiscoveryGrpc.ServiceDiscoveryGrpcClient lbClient =
                new ServiceDiscoveryGrpc.ServiceDiscoveryGrpcClient(lbChannel);

            DiscoverServicesResponse lbResponse = lbClient.DiscoverTopServices(
                new DiscoverServicesRequest
            {
                ServiceName = serviceName,
                MaxCount    = 1
            });

            if (lbResponse.ServiceLocations.Count > 0)
            {
                ServiceLocationMsg serviceLocation = lbResponse.ServiceLocations[0];

                Channel result = GrpcUtils.CreateChannel(serviceLocation.HostName,
                                                         serviceLocation.Port, credentials,
                                                         maxMesssageLength);

                _msg.DebugFormat("The load balancer is suggesting {0}", result.ResolvedTarget);

                return(result);
            }

            // 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.");

            return(null);
        }
Пример #3
0
        protected void OpenChannel(bool useTls, string clientCertificate = null)
        {
            if (string.IsNullOrEmpty(HostName))
            {
                _msg.Debug("Host name is null or empty. No channel opened.");
                return;
            }

            var enoughForLargeGeometries = (int)Math.Pow(1024, 3);

            ChannelCredentials credentials =
                GrpcUtils.CreateChannelCredentials(useTls, clientCertificate);

            Channel = GrpcUtils.CreateChannel(
                HostName, Port, credentials, enoughForLargeGeometries);

            _msg.DebugFormat("Created grpc channel to {0} on port {1}", HostName, Port);

            _healthClient = new Health.HealthClient(Channel);

            ChannelOpenedCore(Channel);
        }