Bird
0
0

Find the mistake in this RabbitMQ sender code snippet:

medium📝 Debug Q7 of 15
Spring Boot - Messaging
Find the mistake in this RabbitMQ sender code snippet:
@Autowired
private RabbitTemplate rabbitTemplate;

public void sendMessage() {
    rabbitTemplate.convertAndSend("", "myQueue", "Hello");
}
ANo error, code is correct
BEmpty exchange name is invalid
CconvertAndSend requires routing key, not queue name
DMethod should return a value
Step-by-Step Solution
Solution:
  1. Step 1: Check exchange parameter

    convertAndSend("", "myQueue", "Hello") uses empty string "" for exchange, which refers to the default exchange. Valid.
  2. Step 2: Verify routing key usage

    "myQueue" as routing key with default exchange correctly sends to queue "myQueue".
  3. Step 3: Confirm no other issues

    @Autowired, method signature, and syntax are correct. No mistakes.
  4. Final Answer:

    No error, code is correct -> Option A
  5. Quick Check:

    Empty exchange means default exchange and is valid [OK]
Quick Trick: Empty exchange means default exchange, valid usage [OK]
Common Mistakes:
  • Confusing routing key with queue name
  • Thinking empty exchange is invalid
  • Expecting method to return a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes