private static Grpc.Core.Server StartServer([NotNull] MicroserverArguments arguments, out IServiceHealth health) { // TODO: Move to ProSuite var healthService = new HealthServiceImpl(); health = null; // new ServiceHealth(healthService); int maxThreadCount = arguments.MaxParallel; if (maxThreadCount <= 0) { maxThreadCount = Environment.ProcessorCount - 1; } var taskScheduler = new StaTaskScheduler(maxThreadCount); var removeOverlapsServiceImpl = new RemoveOverlapsGrpcImpl(taskScheduler) { //Health = health }; var advancedReshapeServiceImpl = new AdvancedReshapeGrpcImpl(taskScheduler); var changeAlongServiceImpl = new ChangeAlongGrpcImpl(taskScheduler); //health.SetStatus(removeOverlapsServiceImpl.GetType(), true); ServerCredentials serverCredentials = GrpcServerUtils.GetServerCredentials(arguments.Certificate, arguments.PrivateKeyFile); var oneGb = (int)Math.Pow(1024, 3); IList <ChannelOption> channelOptions = GrpcServerUtils.CreateChannelOptions(oneGb); var server = new Grpc.Core.Server(channelOptions) { Services = { RemoveOverlapsGrpc.BindService(removeOverlapsServiceImpl), ReshapeGrpc.BindService(advancedReshapeServiceImpl), ChangeAlongGrpc.BindService(changeAlongServiceImpl) //Health.BindService(healthService) }, Ports = { new ServerPort(arguments.HostName, arguments.Port, serverCredentials) } }; server.Start(); _msg.InfoFormat("Service is listening on host {0}, port {1}.", arguments.HostName, arguments.Port); return(server); }
private Server StartLoadBalancerService([NotNull] ServiceRegistry serviceRegistry, [NotNull] LoadBalancerConfig loadBalancerConfig) { ServerCredentials serverCredentials = GrpcServerUtils.GetServerCredentials(loadBalancerConfig.Certificate, loadBalancerConfig.PrivateKeyFile, loadBalancerConfig.EnforceMutualTls); var serviceDiscoveryGrpcImpl = new ServiceDiscoveryGrpcImpl(serviceRegistry) { RemoveUnhealthyServices = !_keyValueStoreIsLocal, WorkerResponseTimeoutSeconds = loadBalancerConfig.ServiceResponseTimeoutSeconds, RecentlyUsedServiceTimeoutSeconds = loadBalancerConfig.RecentlyUsedTimeoutSeconds }; var health = new HealthServiceImpl(); serviceDiscoveryGrpcImpl.Health = health; // General status: health.SetStatus(string.Empty, HealthCheckResponse.Types.ServingStatus.Serving); // Specifically the LB service: health.SetStatus(serviceDiscoveryGrpcImpl.ServiceName, HealthCheckResponse.Types.ServingStatus.Serving); _logger.LogInformation("Starting load-balancer service at {host}:{port}", loadBalancerConfig.HostName, loadBalancerConfig.Port); var server = new Server { Services = { ServiceDiscoveryGrpc.BindService(serviceDiscoveryGrpcImpl), Health.BindService(health) }, Ports = { new ServerPort(loadBalancerConfig.HostName, loadBalancerConfig.Port, serverCredentials) } }; server.Start(); string protocol = serverCredentials == ServerCredentials.Insecure ? "http" : "https"; _logger.LogInformation( "Load balancer service is serving at {protocol}://{host}:{port}", protocol, loadBalancerConfig.HostName, loadBalancerConfig.Port); return(server); }