Big Data 6 min read

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.

Architect Chen
Architect Chen
Architect Chen
Comprehensive Guide to Kafka Core Commands (2026 Edition)

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 --version

Example output: 3.9.0.

2. Create a Topic

kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --create \
  --topic order \
  --partitions 3 \
  --replication-factor 2

Parameters: --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 \
  --list

4. Describe a Topic

kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --describe \
  --topic order

Typical output includes Partition, Leader, ISR, Replicas, etc.

5. Increase Topic Partitions

kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --alter \
  --topic order \
  --partitions 6
Kafka can only increase partitions; it cannot decrease them.

6. Delete a Topic

kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --delete \
  --topic order

Broker configuration delete.topic.enable=true must be set.

7. Produce Messages (Console Producer)

kafka-console-producer.sh \
  --bootstrap-server localhost:9092 \
  --topic order

Type 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 order

By 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 \
  --list

10. Describe a Consumer Group

kafka-consumer-groups.sh \
  --bootstrap-server localhost:9092 \
  --describe \
  --group order

Key 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 order

Commonly used for data replay or testing.

12. View Broker Information

kafka-broker-api-versions.sh \
  --bootstrap-server localhost:9092

Shows broker IDs, API versions, and supported capabilities.

13. View Log Directories

kafka-log-dirs.sh \
  --bootstrap-server localhost:9092 \
  --describe

Outputs 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:9092

Result fields: Records/sec, MB/sec, Latency.

15. Consumer Performance Test

kafka-consumer-perf-test.sh \
  --bootstrap-server localhost:9092 \
  --topic test \
  --messages 100000

Result fields: MB/sec, Messages/sec.

These commands provide a complete toolbox for operating, troubleshooting, and benchmarking a Kafka cluster.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

stream-processingperformance-testingKafkaconsumer-grouptopic-managementbroker-infokafka-cli
Architect Chen
Written by

Architect Chen

Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.