Пример #1
0
        public IConsumer <TKey, TValue> Build()
        {
            Confluent.Kafka.IConsumer <TKey, TValue> consumer = null;

            try
            {
                if (_brokerList.Count == 0)
                {
                    throw new InvalidOperationException($"One broker must be added to build a consumer. Use the {nameof(AddBroker)} method to add a broker!");
                }

                _configuration["bootstrap.servers"] = String.Join(", ", _brokerList.ToArray());
                var builder = new Confluent.Kafka.ConsumerBuilder <TKey, TValue>(_configuration.Select(kp => new KeyValuePair <string, string>(kp.Key, kp.Value.ToString())).AsEnumerable());
                SetHandlers(builder);

                consumer = builder.Build();

                return(consumer);
            }
            finally
            {
                if (_subscribeOnBuild)
                {
                    consumer.Subscribe(_topics);
                }
            }
        }
Пример #2
0
        public KafkaConsumer(Confluent.Kafka.IConsumer <TKey, TValue> kafkaConsumer, IKafkaSubscriptionHandler <TKey, TValue> subscriptionHandler, ILogger <KafkaConsumer <TKey, TValue> > logger)
        {
            this._kafkaConsumer       = kafkaConsumer ?? throw new ArgumentNullException(nameof(kafkaConsumer));
            this._subscriptionHandler = subscriptionHandler ?? throw new ArgumentNullException(nameof(subscriptionHandler));
            this._logger = logger ?? throw new ArgumentNullException(nameof(logger));

            this._subscriptionHandler.SubscriptionChanged += OnSubscriptionChanged;
        }
Пример #3
0
 public KafkaConsumer(Confluent.Kafka.IConsumer <TKey, TValue> consumer, string topic)
 {
     _consumer = consumer;
     _topic    = topic;
 }
Пример #4
0
 public Commitable(ConsumeResult <TKey, TValue> consumeResult, Confluent.Kafka.IConsumer <TKey, TValue> consumer)
 {
     _consumeResult = consumeResult;
     _consumer      = consumer;
 }
Пример #5
0
 [Factory] public static IConsumer <TKey, TValue> CreateConsumer <TKey, TValue>(Confluent.Kafka.IConsumer <TKey, TValue> consumer, Config config) => new KafkaConsumer <TKey, TValue>(consumer, config.ConsumedTopic);