0
0
Spring Bootframework~20 mins

RabbitMQ integration basics in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RabbitMQ Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Spring Boot RabbitMQ listener receives a message?
Consider a Spring Boot application with a RabbitMQ listener method annotated with @RabbitListener. What is the expected behavior when a message arrives in the queue?
Spring Boot
public class MessageListener {
    @RabbitListener(queues = "testQueue")
    public void receiveMessage(String message) {
        System.out.println("Received: " + message);
    }
}
AThe method is called automatically with the message content as the argument.
BThe method must be called manually after fetching the message from the queue.
CThe message is ignored unless the method returns a value.
DThe listener only logs the message but does not process it.
Attempts:
2 left
💡 Hint
Think about how Spring Boot handles methods annotated with @RabbitListener.
📝 Syntax
intermediate
2:00remaining
Which code snippet correctly declares a RabbitMQ queue bean in Spring Boot?
You want to declare a RabbitMQ queue named "myQueue" as a Spring bean. Which option is correct?
A
public Queue myQueue() {
    return new Queue("myQueue", false);
}
B
@Bean
public Queue myQueue() {
    return new Queue("myQueue");
}
C
@Bean
public Queue myQueue() {
    return new Queue();
}
D
@Bean
public Queue myQueue() {
    return new Queue("myQueue", true);
}
Attempts:
2 left
💡 Hint
Remember that @Bean annotation is needed and the constructor requires queue name and durability.
🔧 Debug
advanced
2:00remaining
Why does this Spring Boot RabbitMQ listener fail to receive messages?
Given the code below, why does the listener not receive any messages from the queue?
Spring Boot
public class Listener {
    @RabbitListener(queues = "orders")
    public void listen(String msg) {
        System.out.println("Order: " + msg);
    }
}

// Application properties:
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672

// No queue bean declared in configuration.
AThe listener method signature is incorrect; it must return a value.
BThe listener class must be annotated with @Component to be detected.
CThe RabbitMQ host and port are missing in application properties.
DThe queue 'orders' is not declared as a bean or created, so it does not exist in RabbitMQ.
Attempts:
2 left
💡 Hint
Check if the listener class is a Spring-managed bean.
state_output
advanced
2:00remaining
What is the output when sending a message with RabbitTemplate?
Given the code below, what will be printed to the console?
Spring Boot
public class Sender {
    private final RabbitTemplate rabbitTemplate;

    public Sender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void send() {
        rabbitTemplate.convertAndSend("myExchange", "myRoutingKey", "Hello World");
        System.out.println("Message sent");
    }
}

// Assume exchange and queue are properly configured and bound.
AMessage sent
BHello World
CError: exchange not found
DNo output
Attempts:
2 left
💡 Hint
Focus on what the code explicitly prints.
🧠 Conceptual
expert
2:00remaining
Which statement best describes the role of RabbitMQ exchanges in Spring Boot integration?
In Spring Boot RabbitMQ integration, what is the primary role of an exchange?
AAn exchange stores messages until consumers retrieve them.
BAn exchange is a client that sends messages to RabbitMQ.
CAn exchange routes messages to queues based on routing keys and binding rules.
DAn exchange encrypts messages before sending them to queues.
Attempts:
2 left
💡 Hint
Think about how messages find their way to queues.