Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            var channel             = new Channel(ServerAddress, ChannelCredentials.Insecure);
            var healthCheckClient   = new Health.HealthClient(channel);
            var healthCheckResponse = healthCheckClient.Check(new HealthCheckRequest {
                Service = ServiceName
            });

            Console.WriteLine($"Service: '{ServiceName}' has a health status: {healthCheckResponse.Status.ToString()}");
            try
            {
                healthCheckClient.Check(new HealthCheckRequest {
                    Service = "Bad Name"
                });
            }
            catch (RpcException ex)
            {
                Console.WriteLine($"Service: 'Bad Name' has a health status: {ex.Status.StatusCode.ToString()}");
            }

            var bookClient = new BookService.BookServiceClient(channel);
            var book       = bookClient.GetBookById(new GetBookByIdRequest {
                Id = 1
            });

            Console.WriteLine($"Retrieved book: {book.Name}");

            channel.ShutdownAsync().GetAwaiter().GetResult();

            Console.WriteLine("Press key to shut down ... .. .");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the check.");
            Console.ReadKey(true);


            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new Health.HealthClient(channel);
            var req     = new HealthCheckRequest
            {
                Service = "Liveness"
            };

            try
            {
                var res = client.Check(req);
                Console.WriteLine(res.Status);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines whether the specified endpoint is connected to the specified service
        /// that responds with health status 'Serving' .
        /// </summary>
        /// <param name="healthClient"></param>
        /// <param name="serviceName"></param>
        /// <param name="statusCode">Status code from the RPC call</param>
        /// <returns></returns>
        public static bool IsServing([NotNull] Health.HealthClient healthClient,
                                     [NotNull] string serviceName,
                                     out StatusCode statusCode)
        {
            statusCode = StatusCode.Unknown;

            try
            {
                HealthCheckResponse healthResponse =
                    healthClient.Check(new HealthCheckRequest()
                {
                    Service = serviceName
                });

                statusCode = StatusCode.OK;

                return(healthResponse.Status == HealthCheckResponse.Types.ServingStatus.Serving);
            }
            catch (RpcException rpcException)
            {
                _msg.Debug($"Error checking health of service {serviceName}", rpcException);

                statusCode = rpcException.StatusCode;
            }
            catch (Exception e)
            {
                _msg.Debug($"Error checking health of service {serviceName}", e);
                return(false);
            }

            return(false);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var httpHandler = new HttpClientHandler();

// Return `true` to allow certificates that are untrusted/invalid
            httpHandler.ServerCertificateCustomValidationCallback =
                HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            var channel = GrpcChannel.ForAddress("https://localhost:50051",
                                                 new GrpcChannelOptions {
                HttpHandler = httpHandler
            });

            // var client = new Greet.GreeterClient(channel);
            //
            //
            // var channelTarget = $"{DefaultHost}:{Port}";
            //
            // var channel = new Channel(channelTarget, ChannelCredentials.Insecure);

            Health.HealthClient cc = new Health.HealthClient(channel);
            var c = cc.Check(new HealthCheckRequest());

            Console.WriteLine(c.Status);

            // Create a channel
            // Hello.HelloClient client = new Hello.HelloClient(channel);
            //
            // for (int i = 0; i < 10; i++)
            // {
            //     var reply = client.SayHello(new HelloRequest{Name = "Vincent"});
            //
            //     Console.WriteLine(reply.Message);
            // }
        }
Exemplo n.º 5
0
        public void HealthCheck()
        {
            var client   = new Health.HealthClient(_channel);
            var response = client.Check(new HealthCheckRequest
            {
                Service = ""
            });

            Console.WriteLine(response.Status);
        }
Exemplo n.º 6
0
        private void DoCheck(object state)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:8001");;
            var client = new Health.HealthClient(channel);

            client.Check(new HealthCheckRequest()
            {
                Service = "https://localhost:8001"
            });
        }
Exemplo n.º 7
0
        public async Task Run()
        {
            var host = config.GetValue("GRPC_HOST", "localhost");
            var port = config.GetValue("GRPC_PORT", "50051");

            this.Context.Logger.LogInformation($"connect to the server. {host}:{port}");
            Channel channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure);

            this.Context.Logger.LogInformation($"* Begin Greet Check");
            var    greeter = new Greeter.GreeterClient(channel);
            String user    = "******";
            var    greet   = greeter.SayHello(new HelloRequest {
                Name = user
            });

            this.Context.Logger.LogInformation("Greeting: " + greet.Message);

            this.Context.Logger.LogInformation($"* Begin Version Check");
            var myversion = new MyVersionInfo.MyVersionInfoClient(channel);
            var v         = myversion.Get(new MyVersionInfoRequest
            {
                Message = "hoge",
            });

            this.Context.Logger.LogInformation(v.Version + $"({v.Guid})");

            this.Context.Logger.LogInformation($"* Begin Health Check");
            var health   = new Health.HealthClient(channel);
            var response = health.Check(new HealthCheckRequest
            {
                Service = "Check"
            });

            this.Context.Logger.LogInformation($"Health Checked: {response.Status}");
            channel.ShutdownAsync().Wait();
        }