Bird
0
0

Why does this Kafka producer code fail?

medium📝 Debug Q7 of 15
Spring Boot - Messaging
Why does this Kafka producer code fail?
@Autowired
private KafkaTemplate kafkaTemplate;

public void sendMessage() {
    kafkaTemplate.send();
}
AKafkaTemplate only supports Integer messages
Bsend() requires topic and message parameters
Csend() returns void and cannot be called
DKafkaTemplate must be manually instantiated
Step-by-Step Solution
Solution:
  1. Step 1: Check KafkaTemplate send method signature

    send() requires at least topic name and message as parameters.
  2. Step 2: Validate other options

    KafkaTemplate is injected by Spring; send() returns a ListenableFuture; it supports String messages as declared.
  3. Final Answer:

    send() requires topic and message parameters -> Option B
  4. Quick Check:

    send() needs topic and message [OK]
Quick Trick: Always provide topic and message to send() [OK]
Common Mistakes:
  • Calling send() without parameters
  • Trying to instantiate KafkaTemplate manually
  • Assuming send() returns void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes