Spring Messaging MCQ - Multiple Choice Questions and Answers

The Spring Messaging module brings the power of messaging to Spring-based applications, offering a range of functionalities from simple notifications to complex message-driven systems. Whether you're just starting with messaging in Spring or need a quick refresher, this MCQ guide is designed to test and enhance your foundational knowledge of Spring Messaging.

Note that each question is followed by the correct answer and an explanation to help reinforce your knowledge.

1. Which Spring project provides support for messaging protocols like MQTT, STOMP, and WebSocket?

a) Spring AMQP
b) Spring Kafka
c) Spring Data
d) Spring WebFlux

Answer:

a) Spring AMQP

Explanation:

Spring AMQP provides support for the Advanced Message Queuing Protocol (AMQP) which includes messaging protocols like MQTT and STOMP.

2. In Spring Messaging, which annotation is used to mark a method to be triggered by a message?

a) @MessageListener
b) @EventListener
c) @ReceiveMessage
d) @OnMessage

Answer:

a) @MessageListener

Explanation:

The @MessageListener annotation marks a method to be triggered when a message arrives.

3. Which interface is primarily responsible for sending messages in Spring Messaging?

a) JmsTemplate
b) MessageSender
c) Messenger
d) JmsProducer

Answer:

a) JmsTemplate

Explanation:

JmsTemplate is the core class in Spring Messaging for sending messages.

4. What is the core interface for message consumption in Spring?

a) MessageConsumer
b) MessageReceiver
c) JmsListener
d) JmsConsumer

Answer:

a) MessageConsumer

Explanation:

The MessageConsumer interface allows synchronous reception of messages.

5. Which of the following is NOT a header type in Spring Messaging's MessageHeaders?

a) id
b) timestamp
c) duration
d) contentType

Answer:

c) duration

Explanation:

duration is not a predefined header in Spring Messaging's MessageHeaders.

6. Which annotation is used to enable WebSocket message handling in Spring?

a) @EnableWebSocketMessages
b) @EnableWebSocket
c) @WebSocketListener
d) @WebSocketConfig

Answer:

b) @EnableWebSocket

Explanation:

The @EnableWebSocket annotation is used to enable WebSocket-based message handling in Spring.

7. What is the primary annotation to mark a method to handle exceptions from messaging operations in Spring?

a) @HandleException
b) @MessageExceptionHandler
c) @OnMessageError
d) @ExceptionListener

Answer:

b) @MessageExceptionHandler

Explanation:

The @MessageExceptionHandler annotation marks a method to handle exceptions specifically from messaging operations.

8. In which messaging system does Spring provide first-class support through the Spring Kafka project?

a) RabbitMQ
b) ActiveMQ
c) Apache Kafka
d) MQTT

Answer:

c) Apache Kafka

Explanation:

Spring Kafka provides first-class support for the Apache Kafka messaging system.

9. Which Spring module offers support specifically for RabbitMQ?

a) Spring Rabbit
b) Spring AMQP
c) Spring MQ
d) Spring JMS

Answer:

b) Spring AMQP

Explanation:

Spring AMQP offers support specifically for RabbitMQ.

10. Which interface provides methods to convert between Java objects and messaging payloads in Spring?

a) MessageConverter
b) PayloadConverter
c) ObjectMapper
d) MessageTransformer

Answer:

a) MessageConverter

Explanation:

The MessageConverter interface provides methods to convert between Java objects and messaging payloads in Spring.


Related Spring MCQ Posts

Comments