Skip to content

Kafka console operations

Kafka console operations refer to the command-line tools provided by Apache Kafka for managing brokers, producing messages, and consuming messages directly from the terminal.

Server Management

To operate a Kafka broker, the kafka-server-start.sh script is used with the server configuration file (typically config/server.properties).^[kafka-01.md] This configuration file must define a unique broker.id, the log.dirs for storage, and the zookeeper.connect string^[kafka-01.md].

bin/kafka-server-start.sh config/server.properties

You can manage the server process using Shell job control commands: * ctrl + z: Suspend the process. * bg: Resume the process in the background. * jobs -l: List background jobs. * fg %1: Bring a specific job to the foreground^[kafka-01.md].

To stop the broker, use the stop script^[kafka-01.md]:

bin/kafka-server-stop.sh

Console Producer

To send messages manually, use the kafka-console-producer.sh script.^[kafka-01.md] This requires specifying the broker list and the target topic.

bin/kafka-console-producer.sh --broker-list hadoop101:9092 --topic first

Once running, you can type messages into the terminal. Pressing Enter sends the message line to the broker^[kafka-01.md].

Console Consumer

To read messages from a topic, use the kafka-console-consumer.sh script.^[kafka-01.md] The connection is typically established via Zookeeper.

bin/kafka-console-consumer.sh --zookeeper hadoop101:2181 --topic first

Sources

^[kafka-01.md]