Bird
0
0

You want to produce and consume the first message in a Kafka topic named 'orders'. Which sequence of steps correctly achieves this in Python using kafka-python?

hard📝 Application Q15 of 15
Kafka - Basics and Event Streaming
You want to produce and consume the first message in a Kafka topic named 'orders'. Which sequence of steps correctly achieves this in Python using kafka-python?
ACreate KafkaProducer with bootstrap_servers, send message as bytes, flush; create KafkaConsumer with bootstrap_servers and auto_offset_reset='earliest', then read and decode messages
BCreate KafkaConsumer first, then KafkaProducer; send message as string; consumer reads without decoding
CCreate KafkaProducer without bootstrap_servers, send string message; create KafkaConsumer with bootstrap_servers, read messages as bytes
DCreate KafkaProducer with topic parameter, send message; create KafkaConsumer without bootstrap_servers, read and decode messages
Step-by-Step Solution
Solution:
  1. Step 1: Properly create KafkaProducer and send message

    KafkaProducer must be created with bootstrap_servers; messages sent as bytes and flushed to ensure delivery.
  2. Step 2: Properly create KafkaConsumer and read messages

    KafkaConsumer needs bootstrap_servers and auto_offset_reset='earliest' to read from the first message; decode bytes to string when reading.
  3. Final Answer:

    Create KafkaProducer with bootstrap_servers, send message as bytes, flush; create KafkaConsumer with bootstrap_servers and auto_offset_reset='earliest', then read and decode messages -> Option A
  4. Quick Check:

    Correct producer and consumer setup with bytes and decoding [OK]
Quick Trick: Producer sends bytes and flushes; consumer reads earliest and decodes [OK]
Common Mistakes:
  • Creating producer or consumer without bootstrap_servers
  • Sending string instead of bytes
  • Not setting auto_offset_reset to 'earliest'
  • Not decoding message bytes before printing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes