0
0
Spring Bootframework~10 mins

RabbitTemplate for producing in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a message using RabbitTemplate.

Spring Boot
rabbitTemplate.[1]("myQueue", "Hello World!");
Drag options to blanks, or click blank then click option'
Asend
BconvertAndSend
Creceive
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using send without converting the object.
Trying to use receive to send messages.
2fill in blank
medium

Complete the code to send a message to a specific exchange with a routing key.

Spring Boot
rabbitTemplate.convertAndSend("myExchange", [1], "Message content");
Drag options to blanks, or click blank then click option'
A"myRoutingKey"
B"myQueue"
C"default"
D"exchangeKey"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the queue name instead of the routing key.
Using an invalid routing key string.
3fill in blank
hard

Fix the error in sending a message with RabbitTemplate by completing the method call.

Spring Boot
rabbitTemplate.[1]("exchange", "key", new Message("data".getBytes()));
Drag options to blanks, or click blank then click option'
AsendMessage
BconvertAndSend
Csend
Dpublish
Attempts:
3 left
💡 Hint
Common Mistakes
Using convertAndSend with a Message object.
Using non-existent methods like sendMessage.
4fill in blank
hard

Fill both blanks to send a JSON string message with a custom header.

Spring Boot
MessageProperties props = new MessageProperties();
props.setHeader("content-type", [1]);
Message msg = new Message([2].getBytes(), props);
rabbitTemplate.send("exchange", "routingKey", msg);
Drag options to blanks, or click blank then click option'
A"application/json"
B"text/plain"
C{"name":"John"}
D{"age":30}
Attempts:
3 left
💡 Hint
Common Mistakes
Setting wrong content-type header.
Using non-JSON strings as message body.
5fill in blank
hard

Fill all three blanks to send a message with a custom exchange, routing key, and message body.

Spring Boot
String exchange = [1];
String routingKey = [2];
String message = [3];
rabbitTemplate.convertAndSend(exchange, routingKey, message);
Drag options to blanks, or click blank then click option'
A"customExchange"
B"customKey"
C"Hello RabbitMQ!"
D"defaultExchange"
Attempts:
3 left
💡 Hint
Common Mistakes
Using default exchange instead of custom.
Mixing up routing key and exchange names.