Example #1
0
        /// <inheritdoc/>
        public void Start(EndpointVisibility type, EndpointConfiguration configuration, IEnumerable <Service> services)
        {
            try
            {
                var keepAliveTime         = new grpc.ChannelOption("grpc.keepalive_time", 1000);
                var keepAliveTimeout      = new grpc.ChannelOption("grpc.keepalive_timeout_ms", 500);
                var keepAliveWithoutCalls = new grpc.ChannelOption("grpc.keepalive_permit_without_calls", 1);
                _server = new grpc::Server(new[] {
                    keepAliveTime,
                    keepAliveTimeout,
                    keepAliveWithoutCalls
                })
                {
                    Ports =
                    {
                        new grpc.ServerPort("0.0.0.0", configuration.Port, grpc::SslServerCredentials.Insecure)
                    }
                };

                _server
                .Ports
                .ForEach(_ =>
                         _logger.Information($"Starting {type} host on {_.Host}" + (_.Port > 0 ? $" for port {_.Port}" : string.Empty)));

                services.ForEach(_ => _server.Services.Add(_.ServerDefinition));

                _server.Start();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Couldn't start {type} host");
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="InteractionServer"/>
 /// </summary>
 /// <param name="services"><see cref="IInstancesOf{ICanBindInteractionServices}">Binders of interaction services</see></param>
 /// <param name="configuration"><see cref="Configuration"/> for <see cref="Configuration"/></param>
 /// <param name="logger"><see cref="ILogger"/> for logging</param>
 public InteractionServer(
     IInstancesOf <ICanBindInteractionServices> services,
     Configuration configuration,
     ILogger logger)
 {
     _services      = services;
     _logger        = logger;
     _configuration = configuration;
     _server        = CreateServer();
 }
Example #3
0
        grpc::Server CreateServer()
        {
            var serviceDefinitions = _services.SelectMany(_ => _.BindServices());
            var server             = new grpc::Server
            {
                Ports =
                {
                    new grpc.ServerPort("localhost", _configurationManager.Current.Interaction.Port, grpc::SslServerCredentials.Insecure)//,
                    //new grpc.ServerPort($"unix:{_configurationManager.Current.Interaction.UnixSocket}", 0, grpc::SslServerCredentials.Insecure)
                }
            };

            serviceDefinitions.ForEach(server.Services.Add);

            return(server);
        }