Beispiel #1
0
        private async Task RefreshBrokersAsync(Broker[] latestBrokers, CancellationToken token)
        {
            foreach (var broker in latestBrokers)
            {
                var uri = broker.Address;

                if (!brokers.Contains(uri))
                {
                    brokers.Add(uri);
                }

                var currentConnection = connections.TryGetValue(broker.BrokerId);
                if (currentConnection == null)
                {
                    var newConnection = await KafkaConnectionFactory.CreateSimpleKafkaConnectionAsync(uri, token).ConfigureAwait(false);

                    connections.Add(broker.BrokerId, newConnection);
                }
            }
        }
Beispiel #2
0
        private async Task TryToInitialiseFromBrokersAsync(IEnumerable <Uri> brokers, CancellationToken token)
        {
            foreach (var broker in brokers)
            {
                try {
                    var newConnection = await KafkaConnectionFactory.CreateSimpleKafkaConnectionAsync(broker, token).ConfigureAwait(false);

                    var success = await TryToRefreshFromConnectionAsync(newConnection, token).ConfigureAwait(false);

                    if (success)
                    {
                        return;
                    }
                    else
                    {
                        newConnection.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }