Beispiel #1
0
        public KafkaConsumer(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;

            _logger       = serviceProvider.GetService <ILogger <KafkaConsumer <TKey, TValue> > >();
            _kafkaOptions = serviceProvider.GetService <KafkaMessageBusOptions>();
        }
Beispiel #2
0
        public KafkaProducer(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;

            _logger       = serviceProvider.GetService <ILogger <KafkaProducer <TKey, TValue> > >();
            _kafkaOptions = serviceProvider.GetService <KafkaMessageBusOptions>();

            this.CreateProducer();
        }
Beispiel #3
0
        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)
            {
                //消费者连接订阅时再创建
            }
        }
Beispiel #4
0
        public static IServiceCollection AddKafkaMessageBus(this IServiceCollection services, KafkaMessageBusOptions options)
        {
            services
            .AddSingleton <KafkaMessageBusOptions>(options)
            .AddSingleton <IMessageBus, KafkaMessageBus>();

            return(services);
        }