private void ReadConnections(ConfigParams connections)
 {
     lock (_lock)
     {
         _items.Clear();
         foreach (var entry in connections)
         {
             var item = new DiscoveryItem()
             {
                 Key        = entry.Key,
                 Connection = ConnectionParams.FromString(entry.Value)
             };
             _items.Add(item);
         }
     }
 }
        public async Task <ConnectionParams> ResolveOneAsync(string correlationId, string key)
        {
            ConnectionParams connection = null;

            lock (_lock)
            {
                foreach (var item in _items)
                {
                    if (item.Key == key && item.Connection != null)
                    {
                        connection = item.Connection;
                        break;
                    }
                }
            }

            return(await Task.FromResult(connection));
        }
예제 #3
0
        public async Task <List <ConnectionParams> > ResolveAllAsync(string correlationId)
        {
            var resolved  = new List <ConnectionParams>();
            var toResolve = new List <ConnectionParams>();

            // Sort connections
            foreach (var connection in _connections)
            {
                if (connection.UseDiscovery)
                {
                    toResolve.Add(connection);
                }
                else
                {
                    resolved.Add(connection);
                }
            }

            // Resolve addresses that require that
            if (toResolve.Count <= 0)
            {
                return(resolved);
            }

            foreach (var connection in toResolve)
            {
                var resolvedConnections = await ResolveAllInDiscoveryAsync(correlationId, connection);

                foreach (var resolvedConnection in resolvedConnections)
                {
                    // Merge configured and new parameters
                    var localResolvedConnection = new ConnectionParams(ConfigParams.MergeConfigs(connection, resolvedConnection));
                    resolved.Add(localResolvedConnection);
                }
            }

            return(resolved);
        }
예제 #4
0
        private async Task <ConnectionParams> ResolveInDiscoveryAsync(string correlationId, ConnectionParams connection)
        {
            if (connection.UseDiscovery == false)
            {
                return(null);
            }

            var key = connection.DiscoveryKey;

            if (_references == null)
            {
                return(null);
            }

            var discoveries = _references.GetOptional <IDiscovery>(new Descriptor("*", "discovery", "*", "*", "*"));

            if (discoveries.Count == 0)
            {
                throw new ConfigException(correlationId, "CANNOT_RESOLVE", "Discovery wasn't found to make resolution");
            }

            foreach (var discovery in discoveries)
            {
                var resolvedConnection = await discovery.ResolveOneAsync(correlationId, key);

                if (resolvedConnection != null)
                {
                    return(resolvedConnection);
                }
            }

            return(null);
        }
예제 #5
0
 public void Add(ConnectionParams connection)
 {
     _connections.Add(connection);
 }
예제 #6
0
 public void Configure(ConfigParams config, bool configAsDefault = true)
 {
     _connections.AddRange(ConnectionParams.ManyFromConfig(config, configAsDefault));
 }