Bird
0
0

What is wrong with this Kafka producer code snippet?

medium📝 Debug Q7 of 15
Kafka - Producers
What is wrong with this Kafka producer code snippet?
ProducerRecord record = new ProducerRecord<>(null, "key1", "value1");
producer.send(record);
AValue cannot be null
BKey cannot be null
CTopic name cannot be null
DNo error, code is valid
Step-by-Step Solution
Solution:
  1. Step 1: Check parameters passed to ProducerRecord

    The topic name is null, which is invalid because Kafka requires a valid topic string.
  2. Step 2: Validate key and value

    Key and value can be null, but topic cannot.
  3. Final Answer:

    Topic name cannot be null -> Option C
  4. Quick Check:

    Topic must be non-null string [OK]
Quick Trick: Topic name must never be null [OK]
Common Mistakes:
  • Thinking key cannot be null
  • Assuming value cannot be null
  • Ignoring topic validation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes