无法管理心跳频率

时间:2019-04-01 10:59:57

标签: c# apache-kafka confluent-kafka

我正在使用Confluent的C#Kafka客户端。当消费者开始消费时,我观察到使用Wireshark每秒向服务器发出大约16个请求。我尝试在使用者配置中设置“ HeartbeatIntervalMs = 3000”,但没有任何改变。如何管理这个频率?

编辑:

请求是一对加密字符。在每对请求中,第一个约为有线的60个字节,第二个约为有线的140个字节。第二个包含单词“ Kafka”和所有已订阅的主题,如果订阅的主题数量很多,这将添加大量数据。

我使用的代码是Confluent的Github页面上的示例代码。我只是添加了HeartbeatIntervalMsSessionTimeoutMs,但它们仍然不会改变请求的频率:

var conf = new ConsumerConfig
        { 
            GroupId = "test-consumer-group",
            BootstrapServers = "localhost:9092",
            // Note: The AutoOffsetReset property determines the start offset in the event
            // there are not yet any committed offsets for the consumer group for the
            // topic/partitions of interest. By default, offsets are committed
            // automatically, so in this example, consumption will only start from the
            // earliest message in the topic 'my-topic' the first time you run the program.
            AutoOffsetReset = AutoOffsetReset.Earliest,
            HeartbeatIntervalMs = 3000,
            SessionTimeoutMs = 10000
        };

        using (var c = new ConsumerBuilder<Ignore, string>(conf).Build())
        {
            c.Subscribe("my-topic");

            CancellationTokenSource cts = new CancellationTokenSource();
            Console.CancelKeyPress += (_, e) => {
                e.Cancel = true; // prevent the process from terminating.
                cts.Cancel();
            };

            try
            {
                while (true)
                {
                    try
                    {
                        var cr = c.Consume(cts.Token);
                        Console.WriteLine($"Consumed message '{cr.Value}' at: '{cr.TopicPartitionOffset}'.");
                    }
                    catch (ConsumeException e)
                    {
                        Console.WriteLine($"Error occured: {e.Error.Reason}");
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // Ensure the consumer leaves the group cleanly and final offsets are committed.
                c.Close();
            }
        }

0 个答案:

没有答案