Challenge - 5 Problems
RabbitTemplate Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this RabbitTemplate send() call do?
Consider this Spring Boot code snippet using RabbitTemplate:
What happens when this line runs?
rabbitTemplate.convertAndSend("myExchange", "myRoutingKey", "Hello World");What happens when this line runs?
Spring Boot
rabbitTemplate.convertAndSend("myExchange", "myRoutingKey", "Hello World");
Attempts:
2 left
💡 Hint
Remember that convertAndSend sends to an exchange with a routing key.
✗ Incorrect
The convertAndSend method sends the message to the specified exchange using the routing key. It does not send directly to a queue unless the default exchange and routing key match a queue name.
📝 Syntax
intermediate2:00remaining
Which option correctly sends a Java object as JSON using RabbitTemplate?
You want to send a Java object as JSON message using RabbitTemplate. Which code snippet is correct?
Attempts:
2 left
💡 Hint
convertAndSend automatically converts objects using configured message converters.
✗ Incorrect
convertAndSend uses the message converter to serialize the object (e.g., to JSON) before sending. The send method requires a Message object, not a plain Java object.
🔧 Debug
advanced2:00remaining
Why does this RabbitTemplate call cause a runtime error?
Given this code:
What error will it cause?
rabbitTemplate.convertAndSend(null, "key", "msg");
What error will it cause?
Spring Boot
rabbitTemplate.convertAndSend(null, "key", "msg");
Attempts:
2 left
💡 Hint
RabbitTemplate handles null exchange name by sending to the default exchange.
✗ Incorrect
RabbitTemplate treats a null exchange name as the default exchange (equivalent to empty string), so no error occurs and the message is sent to the default exchange using the routing key.
❓ state_output
advanced2:00remaining
What is the effect of this RabbitTemplate call with mandatory flag?
Consider this code snippet:
Assuming no queue is bound with routing key "wrongKey", what happens?
rabbitTemplate.setMandatory(true);
rabbitTemplate.convertAndSend("exchange", "wrongKey", "test");Assuming no queue is bound with routing key "wrongKey", what happens?
Spring Boot
rabbitTemplate.setMandatory(true); rabbitTemplate.convertAndSend("exchange", "wrongKey", "test");
Attempts:
2 left
💡 Hint
Mandatory flag controls message return if no queue matches.
✗ Incorrect
When mandatory is true, messages that cannot be routed to any queue are returned to the sender via a ReturnCallback.
🧠 Conceptual
expert2:00remaining
Which statement about RabbitTemplate's convertAndSend is true?
Select the correct statement about RabbitTemplate's convertAndSend method behavior.
Attempts:
2 left
💡 Hint
Think about publisher confirms and synchronous behavior.
✗ Incorrect
If publisher confirms are enabled, convertAndSend waits for broker acknowledgment before returning, blocking the thread. It does not retry automatically or require manual serialization.