Example #1
0
        public GrpcServer(GrpcServerConfig serverConfig, ILogger <GrpcServer> logger)
        {
            _serverInstance = new Server(new List <ChannelOption>
            {
                new ChannelOption("grpc.keepalive_permit_without_calls", 1),
                new ChannelOption("grpc.http2.max_pings_without_data", 0),
                new ChannelOption("grpc.max_receive_message_length", -1),
                new ChannelOption("grpc.max_send_message_length", -1)
            }
                                         )
            {
                Ports =
                {
                    new ServerPort(serverConfig.Host, serverConfig.Port, ServerCredentials.Insecure)
                }
            };
            foreach (var serverService in serverConfig.ServiceDefinitions)
            {
                _serverInstance.Services.Add(serverService);
            }

            _logger = logger;

            _logger.Info($"Initialize gRPC Server on  host:{serverConfig.Host} and port:{serverConfig.Port} ...");
        }
Example #2
0
        public static IGrpcServiceBuilder AddGrpc(this IServiceCollection services, Action <GrpcServerConfig> configServer)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var opts = new GrpcServerConfig();

            configServer?.Invoke(opts);

            services.AddSingleton(opts);
            services.AddSingleton <GrpcServer>();
            services.AddHostedService <GrpcServerHostedService>();

            var serviceBuilder = new GrpcServiceBuilder(services);

            return(serviceBuilder);
        }