Ejemplo n.º 1
0
        public KafkaConsumer(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;

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

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

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

            return(services);
        }