public async Task TestClusterConnectionWithAuthAsync() { var resolver = new NatsConnectionResolver(); resolver.Configure(ConfigParams.FromTuples( "connections.0.protocol", "nats", "connections.0.host", "server1", "connections.0.port", 4222, "connections.1.protocol", "nats", "connections.1.host", "server2", "connections.1.port", 4222, "connections.2.protocol", "nats", "connections.2.host", "server3", "connections.2.port", 4222, "credential.username", "test", "credential.password", "pass123", "credential.token", "ABC" )); var connection = await resolver.ResolveAsync(null); Assert.Equal("nats://server1:4222,nats://server2:4222,nats://server3:4222", connection.GetAsString("uri")); Assert.Equal("test", connection.GetAsString("username")); Assert.Equal("pass123", connection.GetAsString("password")); Assert.Equal("ABC", connection.GetAsString("token")); }
/// <summary> /// Configure are configures component by passing configuration parameters. /// </summary> /// <param name="config">Configuration parameters to be set</param> public void Configure(ConfigParams config) { config = config.SetDefaults(_defaultConfig); _connectionResolver.Configure(config); _logger.Configure(config); _options = _options.Override(config.GetSection("options")); _clientId = config.GetAsStringWithDefault("client_id", _clientId); _retryConnect = config.GetAsBooleanWithDefault("options.retry_connect", _retryConnect); _maxReconnect = config.GetAsIntegerWithDefault("options.max_reconnect", _maxReconnect); _reconnectTimeout = config.GetAsIntegerWithDefault("options.reconnect_timeout", _reconnectTimeout); _flushTimeout = config.GetAsIntegerWithDefault("options.flush_timeout", _flushTimeout); }
public async Task TestSingleConnectionAsync() { var resolver = new NatsConnectionResolver(); resolver.Configure(ConfigParams.FromTuples( "connection.protocol", "nats", "connection.host", "localhost", "connection.port", 4222 )); var connection = await resolver.ResolveAsync(null); Assert.Equal("nats://localhost:4222", connection.GetAsString("uri")); Assert.Null(connection.GetAsString("username")); Assert.Null(connection.GetAsString("password")); Assert.Null(connection.GetAsString("token")); }