public static KafkaConfigSettings InitializeKafka(IServiceCollection services, IConfiguration configuration)
        {
            KafkaConfigSettings kafkaConfigSettings = new KafkaConfigSettings();

            configuration.Bind("KafkaConfigSettings", kafkaConfigSettings);

            services.AddSingleton <KafkaConfigSettings>(kafkaConfigSettings);
            services.AddSingleton <IKafkaConfiguration, KafkaConfiguration>();
            services.AddSingleton <IKafkaPublisher, KafkaPublisher>();
            services.AddSingleton <IConsumer <string, string>, Consumer <string, string> >(
                s => new Consumer <string, string>(new KafkaConfiguration(kafkaConfigSettings).ConsumerConfig)
                );
            services.AddSingleton <IKafkaConsumer, KafkaConsumer>();
            services.AddSingleton <IProducer <string, string> >(s => new Producer <string, string>(
                                                                    new KafkaConfiguration(kafkaConfigSettings).ProducerConfig)
                                                                );
            return(kafkaConfigSettings);
        }
Exemplo n.º 2
0
 public KafkaConfiguration(KafkaConfigSettings kafkaConfigSettings)
 {
     _kafkaConfigSettings = kafkaConfigSettings;
 }