示例#1
0
        public IConsumer <byte[], byte[]> GetConsumer(ConsumerConfig config, IConsumerRebalanceListener rebalanceListener)
        {
            ConsumerBuilder <byte[], byte[]> builder = builderKafkaHandler.GetConsumerBuilder(config);

            if (rebalanceListener != null)
            {
                builder.SetPartitionsAssignedHandler((c, p) => rebalanceListener.PartitionsAssigned(c, p));
                builder.SetPartitionsRevokedHandler((c, p) => rebalanceListener.PartitionsRevoked(c, p));
                builder.SetLogHandler(loggerAdapter.LogConsume);
                builder.SetErrorHandler(loggerAdapter.ErrorConsume);
                if (exposeLibrdKafka)
                {
                    // TODO : test librdkafka statistics with IntegrationTest (WIP see #82)
                    var consumerStatisticsHandler = new ConsumerStatisticsHandler(
                        config.ClientId,
                        streamConfig.ApplicationId,
                        (config as StreamizConsumerConfig)?.ThreadId);
                    consumerStatisticsHandler.Register(MetricsRegistry);
                    builder.SetStatisticsHandler((c, stat) =>
                    {
                        var statistics = JsonConvert.DeserializeObject <Statistics>(stat);
                        consumerStatisticsHandler.Publish(statistics);
                    });
                }
            }

            return(builder.Build());
        }
示例#2
0
        public void TestRegisterConsumerRemove1BrokerMetrics()
        {
            var consumerStatisticsHandler = new ConsumerStatisticsHandler(
                config.ClientId,
                config.ApplicationId,
                threadId);

            consumerStatisticsHandler.Register(streamMetricsRegistry);

            var sensorLibrdkafkaConsumerMetrics = streamMetricsRegistry
                                                  .GetThreadScopeSensor(threadId)
                                                  .Count(s => s.Name.StartsWith($"{StreamMetricsRegistry.SENSOR_LIBRDKAFKA_LABEL}."));

            Assert.IsTrue(sensorLibrdkafkaConsumerMetrics > 0);

            var statistics = JsonConvert.DeserializeObject <Statistics>(jsonPayload);

            consumerStatisticsHandler.Publish(statistics);

            var sensorTotalBR = streamMetricsRegistry
                                .GetThreadScopeSensor(threadId)
                                .FirstOrDefault(s => s.Name.Contains($"{LibrdKafkaProducerMetrics.TOTAL_BROKER_CONNECTION}"));

            Assert.AreEqual(3, sensorTotalBR.Metrics.Count());

            Thread.Sleep(100);

            var statistics2 = JsonConvert.DeserializeObject <Statistics>(jsonPayloadWithout1Broker);

            consumerStatisticsHandler.Publish(statistics2);

            var sensorTotalBR2 = streamMetricsRegistry
                                 .GetThreadScopeSensor(threadId)
                                 .FirstOrDefault(s => s.Name.Contains($"{LibrdKafkaProducerMetrics.TOTAL_BROKER_CONNECTION}"));

            Assert.AreEqual(2, sensorTotalBR2.Metrics.Count());
        }
示例#3
0
        public void TestRegisterConsumerMetrics()
        {
            var consumerStatisticsHandler = new ConsumerStatisticsHandler(
                config.ClientId,
                config.ApplicationId,
                threadId);

            consumerStatisticsHandler.Register(streamMetricsRegistry);

            var sensorLibrdkafkaConsumerMetrics = streamMetricsRegistry
                                                  .GetThreadScopeSensor(threadId)
                                                  .Count(s => s.Name.StartsWith($"{StreamMetricsRegistry.SENSOR_LIBRDKAFKA_LABEL}."));

            Assert.IsTrue(sensorLibrdkafkaConsumerMetrics > 0);

            var statistics = JsonConvert.DeserializeObject <Statistics>(jsonPayload);

            consumerStatisticsHandler.Publish(statistics);
        }