Exemplo n.º 1
0
        public void Init()
        {
            backendService = new BackendServiceImpl();

            // Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755
            backendServer = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
            {
                Services = { TestService.BindService(backendService) },
                Ports    = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } }
            };
            backendServer.Start();

            xdsInteropClient = new XdsInteropClient(new XdsInteropClient.ClientOptions
            {
                NumChannels   = 1,
                Qps           = 1,
                RpcTimeoutSec = 10,
                Rpc           = "UnaryCall",
                Server        = $"{Host}:{backendServer.Ports.Single().BoundPort}",
            });

            // Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755
            lbStatsServer = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
            {
                Services = { LoadBalancerStatsService.BindService(new LoadBalancerStatsServiceImpl(xdsInteropClient.StatsWatcher)) },
                Ports    = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } }
            };
            lbStatsServer.Start();

            int port = lbStatsServer.Ports.Single().BoundPort;

            lbStatsChannel = new Channel(Host, port, ChannelCredentials.Insecure);
            lbStatsClient  = new LoadBalancerStatsService.LoadBalancerStatsServiceClient(lbStatsChannel);
        }
Exemplo n.º 2
0
        private async Task RunAsync()
        {
            var server = new Server
            {
                Services = { LoadBalancerStatsService.BindService(new LoadBalancerStatsServiceImpl(statsWatcher)) }
            };

            string host = "0.0.0.0";

            server.Ports.Add(host, options.StatsPort, ServerCredentials.Insecure);
            Console.WriteLine($"Running server on {host}:{options.StatsPort}");
            server.Start();

            var cancellationTokenSource = new CancellationTokenSource();

            await RunChannelsAsync(cancellationTokenSource.Token);

            await server.ShutdownAsync();
        }