In Kafka, the commonly used command to view all topics and their partition offsets is the kafka-topics.sh script, which is included with the Kafka installation. You can use the following command to view details of all topics:
shellkafka-topics.sh --bootstrap-server <server-address> --list
This command displays all topics in the Kafka cluster. Here, <server-address> refers to the address of the Kafka broker, typically in the format hostname:port.
To view the partitions and current offsets of a specific topic, use the kafka-consumer-groups.sh tool. First, identify the consumer group name, then run:
shellkafka-consumer-groups.sh --bootstrap-server <server-address> --group <group-name> --describe
This command shows the partition information and offsets for the topics consumed by the specified consumer group. Here, <group-name> refers to the consumer group name.
For example, if you have a Kafka cluster running on your local machine (localhost) at port 9092 with a consumer group named 'test-group', use the following command to view detailed information for the topics consumed by this group:
shellkafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test-group --describe
This will list detailed information, including partitions and offsets, for all topics consumed by 'test-group'.
This covers the steps to view all topics and their partition offsets in Kafka.