Bird
0
0

Given the following Kafka producer code snippet connecting to Amazon MSK, what will be the output if the message is sent successfully?

medium📝 Predict Output Q13 of 15
Kafka - Kubernetes and Cloud Deployment
Given the following Kafka producer code snippet connecting to Amazon MSK, what will be the output if the message is sent successfully?
producer.send(new ProducerRecord<>("my-topic", "key1", "Hello MSK"));
System.out.println("Message sent successfully");
AError: Connection refused
BMessage sent successfully
CNo output
DMessage failed to send
Step-by-Step Solution
Solution:
  1. Step 1: Understand producer.send behavior

    The send method is asynchronous but the print statement runs immediately after.
  2. Step 2: Check output after send call

    Since no error handling is shown and send is called, the print statement will output "Message sent successfully".
  3. Final Answer:

    Message sent successfully -> Option B
  4. Quick Check:

    Producer send + print = Message sent successfully [OK]
Quick Trick: Print after send shows success unless exception thrown [OK]
Common Mistakes:
MISTAKES
  • Assuming send blocks until confirmed
  • Expecting error without exception handling
  • Thinking no output means success

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes