Exemplo n.º 1
0
        public EventStoreClusterClient(Uri address, IPublisher bus,
                                       Func <HttpMessageHandler> httpMessageHandlerFactory = null)
        {
            HttpMessageHandler httpMessageHandler = httpMessageHandlerFactory?.Invoke() ?? new HttpClientHandler {
                ServerCertificateCustomValidationCallback = (message, certificate, chain, errors) => {
                    if (errors != SslPolicyErrors.None)
                    {
                        Log.Error("Certificate validation failed for certificate: {certificate} due to reason {reason}.", certificate, errors);
                    }
                    return(errors == SslPolicyErrors.None);
                }
            };

            _channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions {
                HttpClient = new HttpClient(httpMessageHandler)
                {
                    Timeout = Timeout.InfiniteTimeSpan,
                    DefaultRequestVersion = new Version(2, 0),
                },
                LoggerFactory = new SerilogLoggerFactory()
            });
            var callInvoker = _channel.CreateCallInvoker();

            _gossipClient    = new EventStore.Cluster.Gossip.GossipClient(callInvoker);
            _electionsClient = new EventStore.Cluster.Elections.ElectionsClient(callInvoker);
            _bus             = bus;
        }
Exemplo n.º 2
0
        public EventStoreClusterClient(Uri address, IPublisher bus, Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > serverCertValidator, X509Certificate clientCertificate)
        {
            HttpMessageHandler httpMessageHandler = null;

            if (address.Scheme == Uri.UriSchemeHttps)
            {
                var socketsHttpHandler = new SocketsHttpHandler {
                    SslOptions =
                    {
                        RemoteCertificateValidationCallback = (sender,                         certificate, chain, errors) => {
                            var(isValid, error)             = serverCertValidator(certificate, chain,       errors);
                            if (!isValid && error != null)
                            {
                                Log.Error("Server certificate validation error: {e}", error);
                            }

                            return(isValid);
                        },
                        ClientCertificates                  = new X509CertificateCollection()
                    }
                };
                if (clientCertificate != null)
                {
                    socketsHttpHandler.SslOptions.ClientCertificates.Add(clientCertificate);
                }

                httpMessageHandler = socketsHttpHandler;
            }
            else if (address.Scheme == Uri.UriSchemeHttp)
            {
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
                httpMessageHandler = new SocketsHttpHandler();
            }

            _channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions {
                HttpClient = new HttpClient(httpMessageHandler)
                {
                    Timeout = Timeout.InfiniteTimeSpan,
                    DefaultRequestVersion = new Version(2, 0),
                },
                LoggerFactory = new SerilogLoggerFactory()
            });
            var callInvoker = _channel.CreateCallInvoker();

            _gossipClient    = new EventStore.Cluster.Gossip.GossipClient(callInvoker);
            _electionsClient = new EventStore.Cluster.Elections.ElectionsClient(callInvoker);
            _bus             = bus;
        }
Exemplo n.º 3
0
        public EventStoreClusterClient(Uri address, IPublisher bus, Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > serverCertValidator, Func <X509Certificate> clientCertificateSelector)
        {
            HttpMessageHandler httpMessageHandler = null;

            if (address.Scheme == Uri.UriSchemeHttps)
            {
                var socketsHttpHandler = new SocketsHttpHandler {
                    SslOptions =
                    {
                        CertificateRevocationCheckMode      = X509RevocationMode.NoCheck,
                        RemoteCertificateValidationCallback = (sender,                        certificate,chain, errors) => {
                            var(isValid, error)             = serverCertValidator(certificate,chain,  errors);
                            if (!isValid && error != null)
                            {
                                Log.Error("Server certificate validation error: {e}", error);
                            }

                            return(isValid);
                        },
                        LocalCertificateSelectionCallback   = delegate {
                            return(clientCertificateSelector());
                        }
                    },
                    PooledConnectionLifetime = ESConsts.HttpClientConnectionLifeTime
                };

                httpMessageHandler = socketsHttpHandler;
            }
            else if (address.Scheme == Uri.UriSchemeHttp)
            {
                httpMessageHandler = new SocketsHttpHandler();
            }

            _channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions {
                HttpClient = new HttpClient(httpMessageHandler)
                {
                    Timeout = Timeout.InfiniteTimeSpan,
                    DefaultRequestVersion = new Version(2, 0),
                },
                LoggerFactory = new SerilogLoggerFactory()
            });
            var callInvoker = _channel.CreateCallInvoker();

            _gossipClient    = new EventStore.Cluster.Gossip.GossipClient(callInvoker);
            _electionsClient = new EventStore.Cluster.Elections.ElectionsClient(callInvoker);
            _bus             = bus;
        }
Exemplo n.º 4
0
        public EventStoreClusterClient(Uri address, IPublisher bus,
                                       Func <HttpMessageHandler> httpMessageHandlerFactory = null)
        {
            _channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions {
                HttpClient = new HttpClient(httpMessageHandlerFactory?.Invoke() ?? new HttpClientHandler())
                {
                    Timeout = Timeout.InfiniteTimeSpan,
                    DefaultRequestVersion = new Version(2, 0),
                },
                LoggerFactory = new SerilogLoggerFactory()
            });
            var callInvoker = _channel.CreateCallInvoker();

            _gossipClient    = new EventStore.Cluster.Gossip.GossipClient(callInvoker);
            _electionsClient = new EventStore.Cluster.Elections.ElectionsClient(callInvoker);
            _bus             = bus;
        }