From a technical point of view, you can simply use all the messages from the topic and read them:
Example:
kafka-run-class.sh kafka.tools.SimpleConsumerShell --broker-list localhost:9092 --topic XYZ --partition 0*
However, the kafka.tools.GetOffsetShell
approach will give you offsets, not the actual number of posts in the topic. This means that if the topic is condensed, you will get two different numbers if you count messages, consuming them or reading offsets.
Thematic Compaction: https://kafka.apache.org/documentation.html#design_compactionbasics
source share