[英]Kafka 1.0 Streaming API: message consumption from partitions get delayed
[英]Unable to get Kafka lag from all partitions
有没有办法为分配给同一消费者组的所有消费者找到整个 kafka 滞后?
我只能得到分配分区的延迟。 例如,假设只有一个分区分配给消费者,下面的代码只会为该分区带来延迟。 不适用于其他分区。
Set<TopicPartition> partitionSet = consumer.assignment();
Map<TopicPartition, Long> endOffsets = consumer.endOffsets(partitionSet);
for(TopicPartition tp : partitionSet) {
LOG.info("Topic:{}, EndOffset:{}, currentOffset:{}, LAG:{}",
tp.topic(), endOffsets.get(tp), consumer.position(tp), endOffsets.get(tp)-consumer.position(tp));
}
基本上,想找到所有分区的滞后总和,以了解主题的所有消费者(同一组)滞后多少。
另外,是否有任何类似于 kafka-consumer-groups 的 api,并将 bootstrap-server 和 group 作为参数传递以查找滞后?
./kafka-consumer-groups.sh --bootstrap-server --group --describe
以编程方式实现此目的的正确方法是使用 AdminClient API:
使用listConsumerGroupOffsets()
获取组的已提交偏移量。
获取日志结束偏移量。 目前,您需要启动一个消费者并为步骤 1 中检索到的所有分区调用endOffsets()
。
在 Kafka 2.5(预计将于 2020 年 2 月listOffsets()
)中,有一个新的 AdminClient API 来检索日志结束偏移量listOffsets()
,它将能够单独使用 AdminClient 来检索延迟。
对于每个分区,从日志结束偏移量(步骤 2)中减去提交的偏移量(步骤 1)。
这基本上就是kafka-consumer-groups.sh
在kafka-consumer-groups.sh
所做的事情。 因此,如果需要,请检查此工具的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.