kafka-console-producer.sh: Send messages to a topic.
kafka-console-consumer.sh: Read messages from a topic.
Click to reveal answer
beginner
How do you list all topics in a Kafka cluster using CLI?
Use the command: kafka-topics.sh --list --bootstrap-server <broker_address> to see all topics.
Click to reveal answer
intermediate
What is the role of kafka-consumer-groups.sh tool?
It manages consumer groups, allowing you to view group details, reset offsets, and monitor consumer lag.
Click to reveal answer
beginner
Why is it important to specify --bootstrap-server in Kafka CLI commands?
The --bootstrap-server option tells the CLI which Kafka broker to connect to initially, so it can discover the full cluster and perform operations.
Click to reveal answer
Which Kafka CLI tool is used to create or delete topics?
Akafka-console-producer.sh
Bkafka-topics.sh
Ckafka-consumer-groups.sh
Dkafka-configs.sh
✗ Incorrect
The kafka-topics.sh tool manages topics, including creating and deleting them.
What does the kafka-console-consumer.sh tool do?
AReads messages from a topic
BSends messages to a topic
CManages consumer groups
DConfigures broker settings
✗ Incorrect
kafka-console-consumer.sh reads messages from a Kafka topic and displays them in the console.
Which option is required to specify the Kafka broker address in CLI commands?
A--topic
B--group
C--partitions
D--bootstrap-server
✗ Incorrect
The --bootstrap-server option specifies the Kafka broker address to connect to.
To check the status of consumer groups, which CLI tool should you use?
Akafka-consumer-groups.sh
Bkafka-topics.sh
Ckafka-console-producer.sh
Dkafka-run-class.sh
✗ Incorrect
kafka-consumer-groups.sh is used to manage and monitor consumer groups.
Which Kafka CLI tool allows you to send messages to a topic?
Akafka-topics.sh
Bkafka-console-consumer.sh
Ckafka-console-producer.sh
Dkafka-acls.sh
✗ Incorrect
kafka-console-producer.sh sends messages to a Kafka topic from the command line.
Explain the main functions of Kafka CLI tools and why they are useful.
Think about how you would control Kafka from the command line.
You got /4 concepts.
Describe how you would list all topics and send a message to a topic using Kafka CLI tools.
Focus on the commands and options needed.
You got /3 concepts.
Practice
(1/5)
1. Which Kafka CLI tool is used to create a new topic?
easy
A. kafka-topics.sh --create
B. kafka-console-producer.sh
C. kafka-console-consumer.sh
D. kafka-configs.sh
Solution
Step 1: Identify the tool for topic management
The kafka-topics.sh tool is used to manage topics including creation, deletion, and listing.
Step 2: Confirm the create option usage
Using --create with kafka-topics.sh creates a new topic.
Final Answer:
kafka-topics.sh --create -> Option A
Quick Check:
Topic creation = kafka-topics.sh --create [OK]
Hint: Topic creation always uses kafka-topics.sh with --create [OK]
Common Mistakes:
Confusing producer or consumer tools for topic creation
Using kafka-configs.sh which manages configs, not topics
Omitting --create option
2. Which of the following is the correct syntax to start a Kafka console producer connecting to a server at localhost:9092?
easy
A. kafka-console-producer.sh --connect localhost:9092 --topic mytopic
B. kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic
C. kafka-console-producer.sh --server localhost:9092 --topic mytopic
D. kafka-console-producer.sh --bootstrap-server localhost:9092 --topic mytopic
Solution
Step 1: Identify the correct option for specifying Kafka server
Modern Kafka CLI tools use --bootstrap-server to specify the Kafka server address.
Step 2: Check the full command syntax
The correct syntax includes kafka-console-producer.sh --bootstrap-server localhost:9092 --topic mytopic.
Final Answer:
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic mytopic -> Option D
Quick Check:
Use --bootstrap-server for server address [OK]
Hint: Always use --bootstrap-server to specify Kafka server [OK]
Common Mistakes:
Using deprecated --broker-list instead of --bootstrap-server
Using incorrect flags like --server or --connect
Omitting the --topic option
3. What will be the output of this command if the topic test-topic has 3 messages: kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning --max-messages 2?
medium
A. It will print all 3 messages from test-topic and then exit.
B. It will print the first 2 messages from test-topic and then exit.
C. It will print no messages because --max-messages is ignored.
D. It will print only the last message from test-topic.
Solution
Step 1: Understand the --max-messages option
The --max-messages 2 option limits the consumer to read only 2 messages before exiting.
Step 2: Analyze the command behavior
The command reads from the beginning and stops after printing 2 messages, even though the topic has 3 messages.
Final Answer:
It will print the first 2 messages from test-topic and then exit. -> Option B
Quick Check:
--max-messages limits output count [OK]
Hint: --max-messages limits how many messages are consumed [OK]
Common Mistakes:
Assuming all messages will be printed ignoring --max-messages
Thinking --max-messages prints last messages only
Confusing --from-beginning with consuming only latest messages
4. You run this command but get an error: kafka-console-producer.sh --topic mytopic. What is missing?
medium
A. The --bootstrap-server option specifying the Kafka server address.
B. The --create option to create the topic.
C. The --from-beginning option to read messages.
D. The --max-messages option to limit output.
Solution
Step 1: Identify required options for kafka-console-producer.sh
The producer needs to know which Kafka server to connect to, specified by --bootstrap-server.
Step 2: Check the given command
The command lacks --bootstrap-server, so it cannot connect and throws an error.
Final Answer:
The --bootstrap-server option specifying the Kafka server address. -> Option A
Quick Check:
Producer needs --bootstrap-server to connect [OK]
Hint: Always include --bootstrap-server to avoid connection errors [OK]
Common Mistakes:
Assuming topic creation is automatic without --create
Confusing producer options with consumer options
Adding irrelevant options like --from-beginning for producer
5. You want to list all topics on a Kafka server at localhost:9092. Which command correctly lists the topics?
hard
A. kafka-console-producer.sh --list --bootstrap-server localhost:9092
B. kafka-console-consumer.sh --list --bootstrap-server localhost:9092
C. kafka-topics.sh --list --bootstrap-server localhost:9092
D. kafka-configs.sh --list --bootstrap-server localhost:9092
Solution
Step 1: Identify the tool for listing topics
The kafka-topics.sh tool manages topics and supports the --list option to show all topics.
Step 2: Confirm the correct command syntax
Using --bootstrap-server localhost:9092 specifies the Kafka server to connect to.
Final Answer:
kafka-topics.sh --list --bootstrap-server localhost:9092 -> Option C
Quick Check:
List topics with kafka-topics.sh --list [OK]
Hint: Use kafka-topics.sh with --list to see all topics [OK]