Exemple #1
0
        /// <summary>
        /// Creates a new <see cref="IEventStoreConnection"/> to single node using default <see cref="ConnectionSettings"/>
        /// </summary>
        /// <param name="connectionName">Optional name of connection (will be generated automatically, if not provided)</param>
        /// <param name="connectionSettings">The <see cref="ConnectionSettings"/> to apply to the new connection</param>
        /// <param name="uri">The Uri to connect to. It can be tcp:// to point to a single node or discover:// to discover nodes via dns</param>
        /// <returns>a new <see cref="IEventStoreConnection"/></returns>
        public static IEventStoreConnection Create(ConnectionSettings connectionSettings, Uri uri, string connectionName = null)
        {
            var scheme = uri == null ? "" : uri.Scheme.ToLower();

            connectionSettings = connectionSettings ?? ConnectionSettings.Default;
            var credential = GetCredentialFromUri(uri);

            if (credential != null)
            {
                connectionSettings = new ConnectionSettings(connectionSettings.Log, connectionSettings.VerboseLogging, connectionSettings.MaxQueueSize, connectionSettings.MaxConcurrentItems,
                                                            connectionSettings.MaxRetries, connectionSettings.MaxReconnections, connectionSettings.RequireMaster, connectionSettings.ReconnectionDelay, connectionSettings.OperationTimeout,
                                                            connectionSettings.OperationTimeoutCheckPeriod, credential, connectionSettings.UseSslConnection, connectionSettings.TargetHost,
                                                            connectionSettings.ValidateServer, connectionSettings.FailOnNoServerResponse, connectionSettings.HeartbeatInterval, connectionSettings.HeartbeatTimeout,
                                                            connectionSettings.ClientConnectionTimeout, connectionSettings.ClusterDns, connectionSettings.GossipSeeds, connectionSettings.MaxDiscoverAttempts,
                                                            connectionSettings.ExternalGossipPort, connectionSettings.GossipTimeout, connectionSettings.PreferRandomNode);
            }
            if (scheme == "discover")
            {
                var clusterSettings = new ClusterSettings(uri.Host, connectionSettings.MaxDiscoverAttempts, uri.Port, connectionSettings.GossipTimeout, connectionSettings.PreferRandomNode);
                Ensure.NotNull(connectionSettings, "connectionSettings");
                Ensure.NotNull(clusterSettings, "clusterSettings");

                var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                          clusterSettings.ClusterDns,
                                                                          clusterSettings.MaxDiscoverAttempts,
                                                                          clusterSettings.ExternalGossipPort,
                                                                          clusterSettings.GossipSeeds,
                                                                          clusterSettings.GossipTimeout,
                                                                          clusterSettings.PreferRandomNode);

                return(new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer, connectionName));
            }

            if (scheme == "tcp")
            {
                var tcpEndPoint = GetSingleNodeIPEndPointFrom(uri);
                return(new EventStoreNodeConnection(connectionSettings, null, new StaticEndPointDiscoverer(tcpEndPoint, connectionSettings.UseSslConnection), connectionName));
            }
            if (connectionSettings.GossipSeeds != null && connectionSettings.GossipSeeds.Length > 0)
            {
                var clusterSettings = new ClusterSettings(connectionSettings.GossipSeeds,
                                                          connectionSettings.MaxDiscoverAttempts,
                                                          connectionSettings.GossipTimeout,
                                                          connectionSettings.PreferRandomNode);
                Ensure.NotNull(connectionSettings, "connectionSettings");
                Ensure.NotNull(clusterSettings, "clusterSettings");

                var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                          clusterSettings.ClusterDns,
                                                                          clusterSettings.MaxDiscoverAttempts,
                                                                          clusterSettings.ExternalGossipPort,
                                                                          clusterSettings.GossipSeeds,
                                                                          clusterSettings.GossipTimeout,
                                                                          clusterSettings.PreferRandomNode);

                return(new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer,
                                                    connectionName));
            }
            throw new Exception(string.Format("Unknown scheme for connection '{0}'", scheme));
        }
        internal async Task should_handle_node_preference_from_gossip(
            ClusterMessages.VNodeState nodeState,
            NodePreference nodePreference)
        {
            var response = new ClusterMessages.ClusterInfoDto {
                Members = new[] {
                    new ClusterMessages.MemberInfoDto {
                        State           = nodeState,
                        IsAlive         = true,
                        ExternalTcpIp   = "127.0.0.1",
                        ExternalTcpPort = 1113
                    },
                    new ClusterMessages.MemberInfoDto {
                        State           = ClusterMessages.VNodeState.Unknown,
                        IsAlive         = true,
                        ExternalTcpIp   = "127.0.0.1",
                        ExternalTcpPort = 2113
                    }
                }
            };

            var sut = new ClusterDnsEndPointDiscoverer(new ConsoleLogger(), "dns", 1, 1111,
                                                       new[] { new GossipSeed(new IPEndPoint(IPAddress.Any, 2113)) }, TimeSpan.FromSeconds(1),
                                                       nodePreference,
                                                       new NoCompatibilityMode(),
                                                       new TestHttpClient(response.ToJson()));

            var result = await sut.DiscoverAsync(new IPEndPoint(IPAddress.Any, 1113));

            Assert.Equal(1113, EndPointExtensions.GetPort(result.TcpEndPoint));
        }
        /// <summary>
        /// Creates a new <see cref="IEventStoreConnection"/> to EventStore cluster
        /// using specific <see cref="ConnectionSettings"/> and <see cref="ClusterSettings"/>
        /// </summary>
        /// <param name="connectionSettings">The <see cref="ConnectionSettings"/> to apply to the new connection</param>
        /// <param name="clusterSettings">The <see cref="ClusterSettings"/> that determine cluster behavior.</param>
        /// <param name="connectionName">Optional name of connection (will be generated automatically, if not provided)</param>
        /// <returns>a new <see cref="IEventStoreConnection"/></returns>
        public static IEventStoreConnection Create(ConnectionSettings connectionSettings,
                                                   ClusterSettings clusterSettings, string connectionName = null)
        {
            Ensure.NotNull(connectionSettings, "connectionSettings");
            Ensure.NotNull(clusterSettings, "clusterSettings");

            var handler = connectionSettings.CustomHttpMessageHandler;

            if (handler is null && !connectionSettings.ValidateServer)
            {
                handler = new HttpClientHandler {
                    ServerCertificateCustomValidationCallback = delegate { return(true); }
                };
            }

            var discoverClient     = new HttpAsyncClient(connectionSettings.GossipTimeout, handler);
            var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                      clusterSettings.ClusterDns,
                                                                      clusterSettings.MaxDiscoverAttempts,
                                                                      clusterSettings.HttpPort,
                                                                      clusterSettings.GossipSeeds,
                                                                      clusterSettings.GossipTimeout,
                                                                      clusterSettings.NodePreference,
                                                                      CompatibilityMode.Create(connectionSettings.CompatibilityMode),
                                                                      discoverClient);

            return(new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer,
                                                connectionName));
        }
        /// <summary>
        /// Creates a new <see cref="IEventStoreConnection"/> to single node using default <see cref="ConnectionSettings"/>
        /// </summary>
        /// <param name="connectionName">Optional name of connection (will be generated automatically, if not provided)</param>
        /// <param name="connectionSettings">The <see cref="ConnectionSettings"/> to apply to the new connection</param>
        /// <param name="uri">The Uri to connect to. It can be tcp:// to point to a single node or discover:// to discover nodes via dns</param>
        /// <returns>a new <see cref="IEventStoreConnection"/></returns>
        public static IEventStoreConnection Create(ConnectionSettings connectionSettings, Uri uri, string connectionName = null)
        {
            var scheme = uri == null ? "" : uri.Scheme.ToLower();

            connectionSettings = connectionSettings ?? ConnectionSettings.Default;
            var credential = GetCredentialFromUri(uri);
            if (credential != null)
            {
                connectionSettings = new ConnectionSettings(connectionSettings.Log, connectionSettings.VerboseLogging, connectionSettings.MaxQueueSize, connectionSettings.MaxConcurrentItems,
                connectionSettings.MaxRetries, connectionSettings.MaxReconnections, connectionSettings.RequireMaster, connectionSettings.ReconnectionDelay, connectionSettings.OperationTimeout,
                connectionSettings.OperationTimeoutCheckPeriod, credential, connectionSettings.UseSslConnection, connectionSettings.TargetHost,
                connectionSettings.ValidateServer, connectionSettings.FailOnNoServerResponse, connectionSettings.HeartbeatInterval, connectionSettings.HeartbeatTimeout,
                connectionSettings.ClientConnectionTimeout, connectionSettings.ClusterDns, connectionSettings.GossipSeeds, connectionSettings.MaxDiscoverAttempts,
                connectionSettings.ExternalGossipPort, connectionSettings.GossipTimeout);
            }
            if (scheme == "discover")
            {
                var clusterSettings = new ClusterSettings(uri.Host, connectionSettings.MaxDiscoverAttempts, uri.Port, connectionSettings.GossipTimeout);
                Ensure.NotNull(connectionSettings, "connectionSettings");
                Ensure.NotNull(clusterSettings, "clusterSettings");

                var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                          clusterSettings.ClusterDns,
                                                                          clusterSettings.MaxDiscoverAttempts,
                                                                          clusterSettings.ExternalGossipPort,
                                                                          clusterSettings.GossipSeeds,
                                                                          clusterSettings.GossipTimeout);

                return new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer, connectionName);
            }

            if (scheme == "tcp")
            {
                var tcpEndPoint = GetSingleNodeIPEndPointFrom(uri);
                return new EventStoreNodeConnection(connectionSettings, null, new StaticEndPointDiscoverer(tcpEndPoint, connectionSettings.UseSslConnection), connectionName);
            }
            if (connectionSettings.GossipSeeds != null && connectionSettings.GossipSeeds.Length > 0)
            {
                var clusterSettings = new ClusterSettings(connectionSettings.GossipSeeds,
                    connectionSettings.MaxDiscoverAttempts,
                    connectionSettings.GossipTimeout);
                Ensure.NotNull(connectionSettings, "connectionSettings");
                Ensure.NotNull(clusterSettings, "clusterSettings");

                var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                    clusterSettings.ClusterDns,
                    clusterSettings.MaxDiscoverAttempts,
                    clusterSettings.ExternalGossipPort,
                    clusterSettings.GossipSeeds,
                    clusterSettings.GossipTimeout);

                return new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer,
                    connectionName);
            }
            throw new Exception(string.Format("Unknown scheme for connection '{0}'", scheme));
        }
        internal EventStoreClusterConnection(ConnectionSettings connectionSettings,
                                             ClusterSettings clusterSettings,
                                             string connectionName)
        {

            var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                      clusterSettings.ClusterDns,
                                                                      clusterSettings.MaxDiscoverAttempts,
                                                                      clusterSettings.ManagerExternalHttpPort,
                                                                      clusterSettings.FakeDnsEntries,
                                                                      clusterSettings.GossipTimeout);
            _conn = new EventStoreNodeConnection(connectionSettings, endPointDiscoverer, connectionName);
        }
        internal EventStoreClusterConnection(ConnectionSettings connectionSettings,
                                             ClusterSettings clusterSettings,
                                             string connectionName)
        {
            var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                      clusterSettings.ClusterDns,
                                                                      clusterSettings.MaxDiscoverAttempts,
                                                                      clusterSettings.ManagerExternalHttpPort,
                                                                      clusterSettings.FakeDnsEntries,
                                                                      clusterSettings.GossipTimeout);

            _conn = new EventStoreNodeConnection(connectionSettings, endPointDiscoverer, connectionName);
        }
Exemple #7
0
        /// <summary>
        /// Creates a new <see cref="IEventStoreConnection"/> to EventStore cluster
        /// using specific <see cref="ConnectionSettings"/> and <see cref="ClusterSettings"/>
        /// </summary>
        /// <param name="connectionSettings">The <see cref="ConnectionSettings"/> to apply to the new connection</param>
        /// <param name="clusterSettings">The <see cref="ClusterSettings"/> that determine cluster behavior.</param>
        /// <param name="connectionName">Optional name of connection (will be generated automatically, if not provided)</param>
        /// <returns>a new <see cref="IEventStoreConnection"/></returns>
        public static IEventStoreConnection Create(ConnectionSettings connectionSettings, ClusterSettings clusterSettings, string connectionName = null)
        {
            Ensure.NotNull(connectionSettings, "connectionSettings");
            Ensure.NotNull(clusterSettings, "clusterSettings");

            var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                      clusterSettings.ClusterDns,
                                                                      clusterSettings.MaxDiscoverAttempts,
                                                                      clusterSettings.ExternalGossipPort,
                                                                      clusterSettings.GossipSeeds,
                                                                      clusterSettings.GossipTimeout);

            return(new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer, connectionName));
        }
        /// <summary>
        /// Creates a new <see cref="IEventStoreConnection"/> to EventStore cluster 
        /// using specific <see cref="ConnectionSettings"/> and <see cref="ClusterSettings"/>
        /// </summary>
        /// <param name="connectionSettings">The <see cref="ConnectionSettings"/> to apply to the new connection</param>
        /// <param name="clusterSettings">The <see cref="ClusterSettings"/> that determine cluster behavior.</param>
        /// <param name="connectionName">Optional name of connection (will be generated automatically, if not provided)</param>
        /// <returns>a new <see cref="IEventStoreConnection"/></returns>
        public static IEventStoreConnection Create(ConnectionSettings connectionSettings, ClusterSettings clusterSettings, string connectionName = null)
        {
            Ensure.NotNull(connectionSettings, "connectionSettings");
            Ensure.NotNull(clusterSettings, "clusterSettings");

            var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                      clusterSettings.ClusterDns,
                                                                      clusterSettings.MaxDiscoverAttempts,
                                                                      clusterSettings.ExternalGossipPort,
                                                                      clusterSettings.GossipSeeds,
                                                                      clusterSettings.GossipTimeout);

            return new EventStoreNodeConnection(connectionSettings, endPointDiscoverer, connectionName);
        }
Exemple #9
0
        /// <summary>
        /// Creates a new <see cref="IEventStoreConnection"/> to EventStore cluster
        /// using specific <see cref="ConnectionSettings"/> and <see cref="ClusterSettings"/>
        /// </summary>
        /// <param name="connectionSettings">The <see cref="ConnectionSettings"/> to apply to the new connection</param>
        /// <param name="clusterSettings">The <see cref="ClusterSettings"/> that determine cluster behavior.</param>
        /// <param name="connectionName">Optional name of connection (will be generated automatically, if not provided)</param>
        /// <returns>a new <see cref="IEventStoreConnection"/></returns>
        public static IEventStoreConnection Create(ConnectionSettings connectionSettings,
                                                   ClusterSettings clusterSettings, string connectionName = null)
        {
            Ensure.NotNull(connectionSettings, "connectionSettings");
            Ensure.NotNull(clusterSettings, "clusterSettings");

            var endPointDiscoverer = new ClusterDnsEndPointDiscoverer(connectionSettings.Log,
                                                                      clusterSettings.ClusterDns,
                                                                      clusterSettings.MaxDiscoverAttempts,
                                                                      clusterSettings.HttpPort,
                                                                      clusterSettings.GossipSeeds,
                                                                      clusterSettings.GossipTimeout,
                                                                      clusterSettings.NodePreference,
                                                                      CompatibilityMode.Create(connectionSettings.CompatibilityMode),
                                                                      connectionSettings.CustomHttpMessageHandler);

            return(new EventStoreNodeConnection(connectionSettings, clusterSettings, endPointDiscoverer,
                                                connectionName));
        }