Ejemplo n.º 1
0
        public KafkaProducer(ILogger logger, IConfigurationSection kafkaConfig)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            _logger = logger;
            var config = KafkaConfigReader.Read(kafkaConfig);

            KafkaConfigReader.LogConfig(_logger, config);
            config.Logger += OnLog;
            _producer      = new Producer(config);
        }
Ejemplo n.º 2
0
        public KafkaConsumer(ILogger logger, List <string> topics, IConfigurationSection kafkaConfig, MessageHandler handler)
        {
            _logger  = logger;
            _handler = handler;
            var config = KafkaConfigReader.Read(kafkaConfig);

            config.EnableAutoCommit = false;
            KafkaConfigReader.LogConfig(_logger, config);
            config.Logger = OnLog;
            _consumer     = new EventConsumer(config);
            _consumer.Subscribe(topics);

            _consumer.OnMessage += OnMessage;
            logger.LogInformation("Starting consumer");
            _consumer.Start();
        }