コード例 #1
0
        private void InitializeAndStartGrpcServer(int grpcPort, ServerServiceDefinition[] definitions, int requestCallTokensPerCompletionQueue, GrpcCoreServerOptions?grpcCoreServerOptions)
        {
            Contract.Requires(definitions.Length != 0);

            GrpcEnvironment.WaitUntilInitialized();
            _grpcServer = new Server(GrpcEnvironment.GetServerOptions(grpcCoreServerOptions))
            {
                Ports = { new ServerPort(IPAddress.Any.ToString(), grpcPort, ServerCredentials.Insecure) },
                RequestCallTokensPerCompletionQueue = requestCallTokensPerCompletionQueue,
            };

            foreach (var definition in definitions)
            {
                _grpcServer.Services.Add(definition);
            }

            _grpcServer.Start();
        }
コード例 #2
0
        private void InitializeAndStartGrpcServer(Context context, LocalServerConfiguration config)
        {
            GrpcCoreServerOptions?grpcCoreServerOptions = config.GrpcCoreServerOptions;

            GrpcEnvironment.WaitUntilInitialized();

            bool?encryptionEnabled = grpcCoreServerOptions?.EncryptionEnabled;

            Tracer.Info(context, $"Grpc Encryption Enabled = {encryptionEnabled == true}, Encrypted GRPC Port: {config.EncryptedGrpcPort}, Unencrypted GRPC Port: {config.GrpcPort}");

            _grpcServer = new Server(GrpcEnvironment.GetServerOptions(grpcCoreServerOptions))
            {
                Ports = { new ServerPort(IPAddress.Any.ToString(), config.GrpcPort, ServerCredentials.Insecure) },
                RequestCallTokensPerCompletionQueue = config.RequestCallTokensPerCompletionQueue,
            };

            if (encryptionEnabled == true)
            {
                try
                {
                    ServerCredentials?serverSSLCreds = TryGetEncryptedCredentials(context, grpcCoreServerOptions);
                    if (serverSSLCreds != null)
                    {
                        _grpcServer.Ports.Add(new ServerPort(IPAddress.Any.ToString(), config.EncryptedGrpcPort, serverSSLCreds));
                        Tracer.Debug(context, $"Server creating Encrypted Grpc channel on port {config.EncryptedGrpcPort}");
                    }
                    else
                    {
                        Tracer.Error(context, message: $"Failed to get SSL Credentials. Not creating encrypted Grpc channel.");
                    }
                }
                catch (Exception ex)
                {
                    Tracer.Error(context, ex, $"Creating SSL Secured Grpc Channel Failed.");
                }
            }

            foreach (var endpoint in GrpcEndpoints)
            {
                endpoint.BindServices(_grpcServer.Services);
            }

            _grpcServer.Start();
        }