public KafkaConsumer(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _logger = serviceProvider.GetService <ILogger <KafkaConsumer <TKey, TValue> > >(); _kafkaOptions = serviceProvider.GetService <KafkaMessageBusOptions>(); }
public KafkaProducer(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _logger = serviceProvider.GetService <ILogger <KafkaProducer <TKey, TValue> > >(); _kafkaOptions = serviceProvider.GetService <KafkaMessageBusOptions>(); this.CreateProducer(); }
public KafkaMessageBus(IServiceProvider serviceProvider, ILogger <KafkaMessageBus> logger, KafkaMessageBusOptions kafkaOptions) { _serviceProvider = serviceProvider; _logger = logger; _kafkaOptions = kafkaOptions; if ((kafkaOptions.ClientMode & ClientMode.Producer) == ClientMode.Producer) { this._producer = new KafkaProducer <Null, MessageBusData>(serviceProvider); } if ((kafkaOptions.ClientMode & ClientMode.Consumer) == ClientMode.Consumer) { //消费者连接订阅时再创建 } }
public static IServiceCollection AddKafkaMessageBus(this IServiceCollection services, KafkaMessageBusOptions options) { services .AddSingleton <KafkaMessageBusOptions>(options) .AddSingleton <IMessageBus, KafkaMessageBus>(); return(services); }