Esempio n. 1
0
        public IProducer <TKey, TValue> Build()
        {
            Confluent.Kafka.IProducer <TKey, TValue> producer = null;
            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.ProducerBuilder <TKey, TValue>(_configuration.Select(kp => new KeyValuePair <string, string>(kp.Key, kp.Value.ToString())).AsEnumerable());

            SetHandlers(builder);

            producer = builder.Build();

            return(producer);
        }
Esempio n. 2
0
 public KafkaProducer(Confluent.Kafka.IProducer <TKey, TValue> producer, string topic)
 {
     _producer = producer;
     _topic    = topic;
 }
Esempio n. 3
0
 [Factory] public static IProducer <TKey, TValue> CreateProducer <TKey, TValue>(Confluent.Kafka.IProducer <TKey, TValue> producer, string topic) => new KafkaProducer <TKey, TValue>(producer, topic);