Bird
0
0

Which of the following is the correct way to produce a message to a Kafka topic in Java?

easy📝 Syntax Q3 of 15
Kafka - Event-Driven Architecture
Which of the following is the correct way to produce a message to a Kafka topic in Java?
Aproducer.push("topic", "message");
Bproducer.publish("topic", "message");
Cproducer.send(new ProducerRecord<>("topic", "message"));
Dproducer.write("topic", "message");
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kafka producer API syntax

    The Kafka producer uses send() with a ProducerRecord object to send messages.
  2. Step 2: Verify method names

    Only send() with ProducerRecord is correct; publish, push, write are invalid methods.
  3. Final Answer:

    producer.send(new ProducerRecord<>("topic", "message")); -> Option C
  4. Quick Check:

    Kafka producer uses send() with ProducerRecord [OK]
Quick Trick: Use send() with ProducerRecord to produce messages [OK]
Common Mistakes:
  • Using incorrect method names like publish or push
  • Not wrapping message in ProducerRecord
  • Confusing producer with consumer methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes