Comprehensive Guide to Kafka Core Commands (2026 Edition)
This article walks through the essential Kafka command‑line tools, covering how to check the Kafka version, create, list, describe, alter, and delete topics, manage partitions, produce and consume messages, inspect consumer groups, reset offsets, query broker metadata, view log directories, and run built‑in performance tests for both producers and consumers.
Kafka is a core component of large‑scale architectures. The following sections detail the most common Kafka command‑line operations.
1. View Kafka Version
kafka-topics.sh --versionExample output: 3.9.0.
2. Create a Topic
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--create \
--topic order \
--partitions 3 \
--replication-factor 2Parameters: --bootstrap-server: address of the Kafka broker --topic: name of the new topic --partitions: number of partitions --replication-factor: number of replicas
3. List All Topics
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--list4. Describe a Topic
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--describe \
--topic orderTypical output includes Partition, Leader, ISR, Replicas, etc.
5. Increase Topic Partitions
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--alter \
--topic order \
--partitions 6Kafka can only increase partitions; it cannot decrease them.
6. Delete a Topic
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--delete \
--topic orderBroker configuration delete.topic.enable=true must be set.
7. Produce Messages (Console Producer)
kafka-console-producer.sh \
--bootstrap-server localhost:9092 \
--topic orderType a message (e.g., hello) and press Enter to send it immediately.
8. Consume Messages (Console Consumer)
kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic orderBy default, only new messages are consumed. To read from the beginning, add --from-beginning.
9. List Consumer Groups
kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--list10. Describe a Consumer Group
kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--describe \
--group orderKey fields: CURRENT‑OFFSET, LOG‑END‑OFFSET, LAG. A larger LAG indicates slower consumption.
11. Reset Consumer Offsets
kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--group order \
--reset-offsets \
--to-earliest \
--execute \
--topic orderCommonly used for data replay or testing.
12. View Broker Information
kafka-broker-api-versions.sh \
--bootstrap-server localhost:9092Shows broker IDs, API versions, and supported capabilities.
13. View Log Directories
kafka-log-dirs.sh \
--bootstrap-server localhost:9092 \
--describeOutputs disk usage, topic storage locations, and partition sizes.
14. Producer Performance Test
kafka-producer-perf-test.sh \
--topic test \
--num-records 1000000 \
--record-size 1024 \
--throughput 1 \
--producer-props bootstrap.servers=localhost:9092Result fields: Records/sec, MB/sec, Latency.
15. Consumer Performance Test
kafka-consumer-perf-test.sh \
--bootstrap-server localhost:9092 \
--topic test \
--messages 100000Result fields: MB/sec, Messages/sec.
These commands provide a complete toolbox for operating, troubleshooting, and benchmarking a Kafka cluster.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
