Spring Boot Spring Boot Caching and Messaging 2 — Questions and Answers
Question 1: Which Spring Boot starter is required to use RabbitMQ with Spring AMQP?
- spring-boot-starter-amqp (Correct answer)
- spring-boot-starter-rabbitmq
- spring-boot-starter-messaging
- spring-boot-starter-rabbit
Correct answer: spring-boot-starter-amqp
`spring-boot-starter-amqp` includes `spring-rabbit` and auto-configures `RabbitTemplate` and `SimpleRabbitListenerContainerFactory` for messaging.
Question 2: Which annotation marks a method as a listener for messages from a RabbitMQ queue?
- @MessageListener
- @QueueListener
- @RabbitListener (Correct answer)
- @AmqpConsumer
Correct answer: @RabbitListener
`@RabbitListener(queues = "my-queue")` registers the annotated method as a message consumer that Spring AMQP invokes for each incoming message.
Question 3: What is the role of `RabbitTemplate` in a Spring Boot application?
- It auto-creates queues and exchanges at startup
- It provides methods to send and receive messages to/from RabbitMQ (Correct answer)
- It listens for dead-letter messages automatically
- It configures RabbitMQ connection pooling
Correct answer: It provides methods to send and receive messages to/from RabbitMQ
`RabbitTemplate` is the central Spring AMQP class for synchronous sending, receiving, and request-reply messaging operations against RabbitMQ.
Question 4: Which Spring Boot starter adds Apache Kafka support with auto-configured `KafkaTemplate`?
- spring-boot-starter-kafka (Correct answer)
- spring-boot-starter-data-kafka
- spring-kafka-starter
- spring-boot-starter-messaging-kafka
Correct answer: spring-boot-starter-kafka
`spring-boot-starter-kafka` brings in `spring-kafka` and auto-configures `KafkaTemplate`, `KafkaAdmin`, and consumer/producer factories.
Question 5: What annotation is used to designate a method as a Kafka message consumer in Spring Boot?
- @KafkaConsumer
- @TopicListener
- @KafkaListener (Correct answer)
- @ConsumerMapping
Correct answer: @KafkaListener
`@KafkaListener(topics = "my-topic")` registers the annotated method to receive messages from the specified Kafka topic via a message listener container.
Question 6: In Spring Boot's Kafka auto-configuration, what property sets the address of the Kafka broker?
- spring.kafka.host
- spring.kafka.broker-url
- spring.kafka.bootstrap-servers (Correct answer)
- spring.kafka.server-address
Correct answer: spring.kafka.bootstrap-servers
`spring.kafka.bootstrap-servers` configures the comma-separated list of host:port pairs used to establish the initial connection to the Kafka cluster.
Which Spring Boot starter is required to use RabbitMQ with Spring AMQP?