Bird
0
0

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📝 Predict Output Q13 of 15
Kafka - Basics and Event Streaming
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?
AIt will print all 3 messages from <code>test-topic</code> and then exit.
BIt will print the first 2 messages from <code>test-topic</code> and then exit.
CIt will print no messages because <code>--max-messages</code> is ignored.
DIt will print only the last message from <code>test-topic</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the --max-messages option

    The --max-messages 2 option limits the consumer to read only 2 messages before exiting.
  2. 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.
  3. Final Answer:

    It will print the first 2 messages from test-topic and then exit. -> Option B
  4. Quick Check:

    --max-messages limits output count [OK]
Quick Trick: --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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes