0
0
Spring Bootframework~20 mins

RabbitTemplate for producing in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RabbitTemplate Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this RabbitTemplate send() call do?
Consider this Spring Boot code snippet using RabbitTemplate:
rabbitTemplate.convertAndSend("myExchange", "myRoutingKey", "Hello World");

What happens when this line runs?
Spring Boot
rabbitTemplate.convertAndSend("myExchange", "myRoutingKey", "Hello World");
ASends the message "Hello World" to the exchange named "myExchange" with routing key "myRoutingKey".
BSends the message "Hello World" to the default exchange ignoring the routing key.
CSends the message "Hello World" directly to a queue named "myRoutingKey".
DSends the message "Hello World" to a queue named "myExchange".
Attempts:
2 left
💡 Hint
Remember that convertAndSend sends to an exchange with a routing key.
📝 Syntax
intermediate
2: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?
ArabbitTemplate.send("exchange", "key", myObject);
BrabbitTemplate.convertAndSend("exchange", "key", myObject);
CrabbitTemplate.convertAndSend("exchange", "key", myObject.toString());
DrabbitTemplate.send("exchange", "key", new Message(myObject));
Attempts:
2 left
💡 Hint
convertAndSend automatically converts objects using configured message converters.
🔧 Debug
advanced
2:00remaining
Why does this RabbitTemplate call cause a runtime error?
Given this code:
rabbitTemplate.convertAndSend(null, "key", "msg");

What error will it cause?
Spring Boot
rabbitTemplate.convertAndSend(null, "key", "msg");
AMessageConversionException because message is null.
BIllegalArgumentException because routing key is invalid.
CNo error, message sent to default exchange.
DNullPointerException because exchange name is null.
Attempts:
2 left
💡 Hint
RabbitTemplate handles null exchange name by sending to the default exchange.
state_output
advanced
2:00remaining
What is the effect of this RabbitTemplate call with mandatory flag?
Consider this code snippet:
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");
AThe message is sent but causes an exception in the application.
BThe message is silently dropped by the broker.
CThe message is sent to the default queue.
DThe message is returned to the sender because no queue matches the routing key.
Attempts:
2 left
💡 Hint
Mandatory flag controls message return if no queue matches.
🧠 Conceptual
expert
2:00remaining
Which statement about RabbitTemplate's convertAndSend is true?
Select the correct statement about RabbitTemplate's convertAndSend method behavior.
AconvertAndSend blocks the calling thread until the broker confirms message receipt if publisher confirms are enabled.
BconvertAndSend automatically retries sending messages on failure without additional configuration.
CconvertAndSend requires manual serialization of objects before sending.
DconvertAndSend can only send String messages, not Java objects.
Attempts:
2 left
💡 Hint
Think about publisher confirms and synchronous behavior.