Bird
0
0

Identify the error in this Kafka producer code snippet: producer.send(topic, key, value);

medium📝 Debug Q6 of 15
Kafka - Basics and Event Streaming
Identify the error in this Kafka producer code snippet: producer.send(topic, key, value);
AThe send method requires a ProducerRecord object, not separate parameters.
BThe topic name must be a global variable.
CThe key parameter cannot be null.
DThe producer must be closed before sending.
Step-by-Step Solution
Solution:
  1. Step 1: Review Kafka producer send method

    The send method expects a ProducerRecord object encapsulating topic, key, and value.
  2. Step 2: Analyze code snippet

    Passing topic, key, value as separate parameters is incorrect usage.
  3. Final Answer:

    The send method requires a ProducerRecord object, not separate parameters. -> Option A
  4. Quick Check:

    send() needs ProducerRecord object [OK]
Quick Trick: Use ProducerRecord to send messages, not separate args [OK]
Common Mistakes:
  • Passing parameters directly instead of ProducerRecord
  • Assuming key cannot be null
  • Closing producer before sending messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes