public async Task <IClusterNode> CreateAndConnectAsync(IPEndPoint endPoint) { var connection = await _connectionFactory.CreateAndConnectAsync(endPoint); var serverFeatures = await connection.Hello(_transcoder).ConfigureAwait(false); var errorMap = await connection.GetErrorMap(_transcoder).ConfigureAwait(false); var mechanismType = _clusterContext.ClusterOptions.EnableTls ? MechanismType.Plain : MechanismType.ScramSha1; var saslMechanism = _saslMechanismFactory.Create(mechanismType, _clusterContext.ClusterOptions.UserName ?? throw new ArgumentNullException(nameof(_clusterContext.ClusterOptions.UserName)), _clusterContext.ClusterOptions.Password ?? throw new ArgumentNullException(nameof(_clusterContext.ClusterOptions.Password))); await saslMechanism.AuthenticateAsync(connection, _clusterContext.CancellationToken).ConfigureAwait(false); var clusterNode = new ClusterNode(_clusterContext, _connectionFactory, _logger, _transcoder, _circuitBreaker, _saslMechanismFactory) { EndPoint = endPoint, Connection = connection, ServerFeatures = serverFeatures, ErrorMap = errorMap }; clusterNode.BuildServiceUris(); return(clusterNode); }
protected async Task <IConnection> CreateConnectionAsync(CancellationToken cancellationToken) { var connection = await _connectionFactory.CreateAndConnectAsync(EndPoint, cancellationToken) .ConfigureAwait(false); try { await _connectionInitializer.InitializeConnectionAsync(connection, cancellationToken) .ConfigureAwait(false); if (BucketName != null) { await _connectionInitializer.SelectBucketAsync(connection, BucketName, cancellationToken) .ConfigureAwait(false); } return(connection); } catch { // Be sure to cleanup the connection if bootstrap fails. // Use the synchronous dispose as we don't need to wait for in-flight operations to complete. connection.Dispose(); throw; } }
protected async Task <IConnection> CreateConnectionAsync(CancellationToken cancellationToken) { var connection = await _connectionFactory.CreateAndConnectAsync(EndPoint, cancellationToken) .ConfigureAwait(false); await _connectionInitializer.InitializeConnectionAsync(connection, cancellationToken).ConfigureAwait(false); if (BucketName != null) { await _connectionInitializer.SelectBucketAsync(connection, BucketName, cancellationToken).ConfigureAwait(false); } return(connection); }