Beispiel #1
0
        public KafkaConsumerService(
            IServiceProvider serviceProvider,
            IOptions <KafkaOptions> optionsProvider,
            ILogger <KafkaConsumerService <TMessage> > logger,
            ConsumerConfig consumerConfig,
            KafkaTopicProvider topicProvider)
        {
            _serviceProvider = serviceProvider;
            _logger          = logger;
            _topicProvider   = topicProvider;
            _consumer        = new ConsumerBuilder <Null, TMessage>(consumerConfig)
                               .SetLogHandler((consumer, message) =>
            {
                var logLevel = message.Level.GetLogLevel();
                logger.Log(logLevel, "Kafka log event {Name} ({Facility}) - {Message}", message.Name, message.Facility, message.Message);
            })
                               .SetErrorHandler((consumer, error) =>
            {
                var logLevel = error.GetLogLevel();
                var category = error.GetCategory();

                logger.Log(logLevel, "Kafka consumer error '{Code}' - '{Reason}', category '{Category}'", error.Code, error.Reason, category);
            })
                               .SetValueDeserializer(new JsonDeserializer <TMessage>(optionsProvider.Value.CreateJsonOptions()))
                               .Build();
        }
Beispiel #2
0
 public KafkaTransport(KafkaProducerProvider producerProvider, KafkaTopicProvider topicProvider)
 {
     _producerProvider = producerProvider;
     _topicProvider    = topicProvider;
 }