public KafkaTopicWriter( string topic, IProducerFactory producerFactory, IHandle <TKey, TMessage, TResponseKey, TResponse> handle, Func <TResponse, TResponseKey> resolveKey) { _topic = topic; _resolveKey = resolveKey; _stream = handle.Stream; _producer = producerFactory.Create <TResponseKey, TResponse>(_stream.Configuration); }
public bool Run(string topic, ConsumerConfig consumeConfiguration, IEnumerable <ProducerConfig> produceConfigurations) { _topic = topic; _logger.LogInformation($"Starting feed proxy for topic {_topic}"); try { _consumer = _consumerFactory.Create(_topic, consumeConfiguration); _consumer.Connect(); _logger.LogInformation($"Connect consumer {_consumer.Environment}, topic {_topic}"); } catch (Exception e) { _logger.LogError(e, $"Exception while connect consumer {_consumer.Environment}."); return(false); } foreach (var producerConfiguration in produceConfigurations) { var producer = _producerFactory.Create(_topic, producerConfiguration); try { producer.Connect(); _producers.Add(producer); _logger.LogInformation($"Connect producer {producer.Environment}, topic {_topic}"); } catch (Exception e) { _logger.LogError(e, $"Exception while connect producer {producer.Environment}."); } } if (!_producers.Any()) { _logger.LogWarning($"Doesn't have any connected producers for topic {_topic}, feed proxy not started!"); return(false); } _consumer.Subscribe(Handler); _logger.LogInformation($"Subscribe consumer {_consumer.Environment}, topic {_topic}"); return(true); }