Ejemplo n.º 1
0
        public KafkaConsumer(
            ConsumerConfiguration configuration,
            IConsumerManager consumerManager,
            ILogHandler logHandler,
            IConsumerWorkerPool consumerWorkerPool)
        {
            this.configuration      = configuration;
            this.consumerManager    = consumerManager;
            this.logHandler         = logHandler;
            this.consumerWorkerPool = consumerWorkerPool;

            var kafkaConfig = configuration.GetKafkaConfig();

            this.consumerBuilder = new ConsumerBuilder <byte[], byte[]>(kafkaConfig);

            this.consumerBuilder.SetPartitionsAssignedHandler((consumer, partitions) => this.OnPartitionAssigned(consumer, partitions));
            this.consumerBuilder.SetPartitionsRevokedHandler((consumer, partitions) => this.OnPartitionRevoked(partitions));
        }
Ejemplo n.º 2
0
        public KafkaConsumer(
            ConsumerConfiguration configuration,
            IConsumerManager consumerManager,
            ILogHandler logHandler,
            IConsumerWorkerPool consumerWorkerPool,
            IDependencyResolver dependencyResolver,
            CancellationToken busStopCancellationToken)
        {
            this.Configuration            = configuration;
            this.consumerManager          = consumerManager;
            this.logHandler               = logHandler;
            this.consumerWorkerPool       = consumerWorkerPool;
            this.dependencyResolver       = dependencyResolver;
            this.busStopCancellationToken = busStopCancellationToken;

            var kafkaConfig = configuration.GetKafkaConfig();

            this.consumerBuilder = new ConsumerBuilder <byte[], byte[]>(kafkaConfig);

            this.consumerBuilder
            .SetPartitionsAssignedHandler((consumer, partitions) => this.OnPartitionAssigned(partitions))
            .SetPartitionsRevokedHandler((consumer, partitions) => this.OnPartitionRevoked(partitions))
            .SetErrorHandler(
                (p, error) =>
            {
                if (error.IsFatal)
                {
                    this.logHandler.Error("Kafka Consumer Fatal Error", null, new { Error = error });
                }
                else
                {
                    this.logHandler.Warning("Kafka Consumer Error", new { Error = error });
                }
            })
            .SetStatisticsHandler(
                (consumer, statistics) =>
            {
                foreach (var handler in configuration.StatisticsHandlers)
                {
                    handler.Invoke(statistics);
                }
            });
        }
        public KafkaConsumer(
            ConsumerConfiguration configuration,
            IConsumerManager consumerManager,
            ILogHandler logHandler,
            IConsumerWorkerPool consumerWorkerPool,
            CancellationToken busStopCancellationToken)
        {
            this.configuration            = configuration;
            this.consumerManager          = consumerManager;
            this.logHandler               = logHandler;
            this.consumerWorkerPool       = consumerWorkerPool;
            this.busStopCancellationToken = busStopCancellationToken;

            var kafkaConfig = configuration.GetKafkaConfig();

            this.consumerBuilder = new ConsumerBuilder <byte[], byte[]>(kafkaConfig);

            this.consumerBuilder
            .SetPartitionsAssignedHandler((consumer, partitions) => this.OnPartitionAssigned(consumer, partitions))
            .SetPartitionsRevokedHandler((consumer, partitions) => this.OnPartitionRevoked(partitions))
            .SetErrorHandler((p, error) => this.logHandler.Error("Kafka Consumer Error", null, new { Error = error }));
        }