Kafka主题中的消息数 [英] Kafka Number of messages in a topic

查看:76
本文介绍了Kafka主题中的消息数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要存储kafka主题中的消息数.这与是否有消费者使用了邮件无关.

I need the number of messages in a kafka topic stored. This is not concerned with whether any consumer has consumed the messages or not.

kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092,localhost:9093,localhost:9094 --topic test-topic

上面给出了主题的偏移量编号?

The above gives the offset number for the topic?

以上内容是否等于kafka主题中当前存储的消息数?

Is the above equal to the number of messages currently stored in the kafka topic?

推荐答案

不完全是.您得到的数字仅指所有主题分区的当前最大偏移量.消息数还取决于该主题的分区的起始偏移量.

Not exactly. The numbers you got only refers to the current max offsets of all the topic partitions. Message count also depends on the partitions' beginning offsets for that topic.

您可以运行

kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092,localhost:9093,localhost:9094 --topic测试主题-时间-1

kafka-run-class.sh kafka.tools.GetOffsetShell-经纪人列表localhost:9092,localhost:9093,localhost:9094 --topic test-topic --time -2

分别,通过从endOffsets中减去beginOffsets,然后将它们加起来以获得该主题的总记录数,来计算每个分区的消息计数.

respectively, and calculate the message count for each partition by subtracting beginningOffsets from endOffsets, then sum them up to get the total record count for that topic.

这篇关于Kafka主题中的消息数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆