public EventStoreClient(EventStoreClientSettings settings = null)
        {
            _settings = settings ?? new EventStoreClientSettings();
            var connectionName = _settings.ConnectionName ?? $"ES-{Guid.NewGuid()}";
            Action <Exception> exceptionNotificationHook = null;
            var httpHandler = _settings.CreateHttpMessageHandler?.Invoke() ?? new HttpClientHandler();

            if (_settings.ConnectivitySettings.GossipSeeds.Length > 0)
            {
                ConfigureClusterAwareHandler();
            }

            _channel = GrpcChannel.ForAddress(_settings.ConnectivitySettings.Address, new GrpcChannelOptions {
                HttpClient = new HttpClient(httpHandler)
                {
                    Timeout = Timeout.InfiniteTimeSpan,
                    DefaultRequestVersion = new Version(2, 0),
                },
                LoggerFactory = _settings.LoggerFactory
            });
            var callInvoker = (_settings.Interceptors ?? Array.Empty <Interceptor>()).Aggregate(
                _channel.CreateCallInvoker()
                .Intercept(new TypedExceptionInterceptor(exceptionNotificationHook))
                .Intercept(new ConnectionNameInterceptor(connectionName)),
                (invoker, interceptor) => invoker.Intercept(interceptor));

            _client = new Streams.Streams.StreamsClient(callInvoker);
            PersistentSubscriptions = new EventStorePersistentSubscriptionsClient(callInvoker, _settings);
            ProjectionsManager      = new EventStoreProjectionManagerClient(callInvoker);
            UsersManager            = new EventStoreUserManagerClient(callInvoker);
            _log = _settings.LoggerFactory?.CreateLogger <EventStoreClient>() ?? new NullLogger <EventStoreClient>();

            void ConfigureClusterAwareHandler()
            {
                var clusterAwareHttpHandler = new ClusterAwareHttpHandler(
                    _settings.ConnectivitySettings.NodePreference == NodePreference.Leader,
                    new ClusterEndpointDiscoverer(
                        _settings.ConnectivitySettings.MaxDiscoverAttempts,
                        _settings.ConnectivitySettings.GossipSeeds,
                        _settings.ConnectivitySettings.GossipTimeout,
                        _settings.ConnectivitySettings.DiscoveryInterval,
                        _settings.ConnectivitySettings.NodePreference,
                        httpHandler))
                {
                    InnerHandler = httpHandler
                };

                exceptionNotificationHook = clusterAwareHttpHandler.ExceptionOccurred;
                httpHandler = clusterAwareHttpHandler;
            }
        }
Esempio n. 2
0
        public EventStoreClient(EventStoreClientSettings settings = null)
        {
            settings ??= new EventStoreClientSettings(new UriBuilder {
                Scheme = Uri.UriSchemeHttps,
                Port   = 2113
            }.Uri);
            _channel = GrpcChannel.ForAddress(settings.Address, new GrpcChannelOptions {
                HttpClient = settings.CreateHttpClient?.Invoke()
            });
            var connectionName = settings.ConnectionName ?? $"ES-{Guid.NewGuid()}";

            var callInvoker = settings.Interceptors.Aggregate(
                _channel.CreateCallInvoker()
                .Intercept(new TypedExceptionInterceptor())
                .Intercept(new ConnectionNameInterceptor(connectionName)),
                (invoker, interceptor) => invoker.Intercept(interceptor));

            _client = new Streams.Streams.StreamsClient(callInvoker);
            PersistentSubscriptions = new EventStorePersistentSubscriptionsClient(callInvoker);
            ProjectionsManager      = new EventStoreProjectionManagerClient(callInvoker);
            UsersManager            = new EventStoreUserManagerClient(callInvoker);
        }
Esempio n. 3
0
 public HttpEventStoreProjectionManagerClient(EventStoreClient parent, Func <UserCredentials> defaultCredentials)
 {
     _parent             = parent;
     _defaultCredentials = defaultCredentials;
     _client             = parent.ProjectionsManager;
 }