Master Kafka: Essential Commands for Starting, Managing Topics, and Messaging
This guide walks you through the core Kafka commands for starting and stopping the service, creating, listing, describing, and deleting topics, as well as producing and consuming messages, while explaining key parameters such as Zookeeper, partitions, and replication factors.
1. Start Kafka Service
Run the following command to launch the Kafka broker in daemon mode using the server configuration file:
bin/kafka-server-start.sh -daemon config/server.properties2. Stop Kafka Service
Stop the running Kafka broker with:
./kafka-server-stop.sh3. Create a Topic
Use the kafka-topics.sh script to create a new topic. Example creates a topic named test0 with specific settings:
bin/kafka-topics.sh --create \
--topic test0 \
--zookeeper 127.0.0.1:2181 \
--config max.message.bytes=12800000 \
--config num.partitions=5 \
--replication-factor 14. List All Topics
Display every topic known to the cluster:
bin/kafka-topics.sh --list --zookeeper localhost:90925. Describe Topic Details
Show detailed information for all topics, including partition count and replication factor:
bin/kafka-topics.sh --describe --zookeeper cdh-worker-1:2181/kafka6. View Partition and Replica Information
Inspect the partitions and replica assignment for a specific topic:
bin/kafka-topics.sh --describe \
--zookeeper 127.0.0.1:2181 \
--topic test07. Delete a Topic
Remove an existing topic from the cluster:
bin/kafka-topics.sh --delete \
--zookeeper 127.0.0.1:2181 \
--topic test08. Send Messages (Producer)
Publish messages to a topic using the console producer:
./kafka-console-producer.sh \
--broker-list localhost:9092 \
--topic test9. Receive Messages (Consumer)
Consume messages from the beginning of the topic:
./kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic test \
--from-beginningConsume only new messages arriving after the consumer starts:
./kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic testParameter Explanations
--topic : Name of the topic (e.g., test0).
--zookeeper : Zookeeper connection string, must match the zookeeper.connect setting in server.properties.
--config : Topic‑specific configuration options.
--partitions : Number of partitions for the topic.
--replication-factor : Number of replicas for each partition (default is 1).
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.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
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.
