public async Task StopAsync(CancellationToken cancellationToken)
 {
     if (Interlocked.Exchange(ref _stopped, 1) == 1)
     {
         return;
     }
     await _server.ShutdownAsync();
 }
Ejemplo n.º 2
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            logger.LogInformation("Terminating GRPC Server");

            await server.ShutdownAsync();

            logger.LogInformation("GRPC Server Terminated");
        }
 public void Dispose()
 {
     if (_server == null)
     {
         return;
     }
     AsyncHelper.RunSync(() => _server.ShutdownAsync());
     _server   = null;
     IsStarted = false;
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            const int port = 1337;
            var rpcServer = new global::Grpc.Core.Server
            {
                Services = { BenchmarkService.BindService(new BenchmarkServiceServer()) },
                Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
            };
            rpcServer.Start();

            Console.WriteLine("BenchmarkService server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();
            rpcServer.ShutdownAsync().Wait();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("The gRPC server is starting.");

            var server = new GoogleGrpc.Core.Server
            {
                Services = { Adder.BindService(new AdderService()) },
                Ports    = { new GoogleGrpc.Core.ServerPort("localhost", 50000, GoogleGrpc.Core.ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("The gRPC server is listening.");
            Console.WriteLine();
            Console.WriteLine("Press Enter to shut down the server.");
            Console.ReadLine();

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 6
0
        private static void RunHost()
        {
            MagicOnionServiceDefinition service = MagicOnionEngine.BuildServerServiceDefinition(
                new[] { typeof(UserAccessGrpc) },
                new MagicOnionOptions(isReturnExceptionStackTraceInErrorDetail: true));

            // SSL gRPC
            string caCrt          = File.ReadAllText(EnvVars.CaCrtPath());
            string serverCrt      = File.ReadAllText(EnvVars.ServerCrtPath());
            string serverKey      = File.ReadAllText(EnvVars.ServerKeyPath());
            var    keyPair        = new KeyCertificatePair(serverCrt, serverKey);
            var    sslCredentials = new SslServerCredentials(new List <KeyCertificatePair>()
            {
                keyPair
            }, caCrt, false);

            int localPort = EnvVars.LocalPort(@"UserAccessPort");

            var server = new global::Grpc.Core.Server
            {
                Services = { service },
                Ports    = { new ServerPort("0.0.0.0", localPort, sslCredentials) }
            };

            // launch gRPC Server.
            server.Start();

            Log.Information($"Server listening on port {localPort}");

            var cts = new CancellationTokenSource();

            var syncTask = new TaskCompletionSource <bool>();

            System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += (context) =>
            {
                Log.Information("Greeter server received kill signal...");
                cts.Cancel();
                server.ShutdownAsync().Wait();
                syncTask.SetResult(true);
            };
            syncTask.Task.Wait(-1);
            Log.Information("Greeter server stopped");
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddInfrastructure()
                                  .BuildServiceProvider();

            var server = new global::Grpc.Core.Server
            {
                Services = { ProductionLineService.BindService(new ProductionLineImpl(serviceProvider)) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Production Line server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            const int Port = 50052;

            Console.WriteLine("Starting VirtualWallet server!");

            var server = new global::Grpc.Core.Server
            {
                // TODO: Bind all service implementations here.
                Services = { LegalPersonService.BindService(new LegalPersonServiceImpl()) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("VirtualWallet Server listening at port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }