private static ServiceLoad StartLoadReportingService() { var loadReportingServiceImpl = new LoadReportingGrpcImpl(); var server = new Server { Services = { LoadReportingGrpc.BindService(loadReportingServiceImpl) }, Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) } }; ServiceLoad serviceLoad = new ServiceLoad(); loadReportingServiceImpl.AllowMonitoring(ServiceName, serviceLoad); server.Start(); return(serviceLoad); }
static async Task Main(string[] args) { if (!TryGetArguments(args, out int port, out int secondsUntilUnhealthy, out int currentRequests)) { return; } // The health service every serious grpc server has: var healthService = new HealthServiceImpl(); healthService.SetStatus(_serviceName, HealthCheckResponse.Types.ServingStatus.Serving); // The load reporting service required for Quaestor load-balancer: LoadReportingGrpcImpl loadReporter = new LoadReportingGrpcImpl(); // Use Load.StartRequest(); at the beginning // and Load.StartRequest(); at the end of a request // or assign a known load rate using Load.KnownLoadRate Load = new ServiceLoad { ProcessCapacity = 1, CurrentProcessCount = currentRequests, ServerUtilization = 0.12345 }; loadReporter.AllowMonitoring("Worker", Load); var server = new Server { Services = { // YourGrpc.BindService(yourActualServiceImpl), Health.BindService(healthService), LoadReportingGrpc.BindService(loadReporter) }, Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) } }; server.Start(); if (secondsUntilUnhealthy > 0) { await SetUnhealthyAfter(secondsUntilUnhealthy, healthService); } Console.WriteLine("Press any key to finish."); Console.ReadKey(true); }
private static Grpc.Core.Server StartGrpcServer( MicroserverArguments arguments, [NotNull] QualityVerificationGrpcImpl verificationServiceImpl, [NotNull] HealthServiceImpl healthService, [NotNull] LoadReportingGrpcImpl loadReporting) { var services = new List <ServerServiceDefinition>( new[] { QualityVerificationGrpc.BindService(verificationServiceImpl), Health.BindService(healthService), LoadReportingGrpc.BindService(loadReporting) }); return(StartGrpcServer(services, arguments)); }
private void StartAndRegisterServices(string hostName, int startPort) { for (int port = startPort; port < startPort + _serviceCount; port++) { var healthService = new HealthServiceImpl(); healthService.SetStatus(_serviceName, HealthCheckResponse.Types.ServingStatus.Serving); var loadReportingService = new LoadReportingGrpcImpl(); ServiceLoad serviceLoad = new ServiceLoad(3); loadReportingService.AllowMonitoring(_serviceName, serviceLoad); var server = new Server { Services = { Health.BindService(healthService), LoadReportingGrpc.BindService(loadReportingService) }, Ports = { new ServerPort(hostName, port, ServerCredentials.Insecure) } }; server.Start(); _serviceLoadByLocation.Add(new ServiceLocation(_serviceName, hostName, port, false), serviceLoad); _serviceRegistry.Ensure(_serviceName, hostName, port, false); } }