In Spring AMQP, the MessageListener interface is the callback that receives messages from a RabbitMQ queue. It has one method, onMessage(Message message), which a listener container calls for every message it consumes, on a container-managed thread. The interface is org.springframework.amqp.core.MessageListener.
You can implement it directly, but most Spring Boot applications use @RabbitListener, which builds on the same container machinery and converts messages to Java objects for you. Knowing the interface explains what the container does and when a lower-level listener is still useful.
The interface is tiny:
The org.springframework.amqp.core.Message argument carries the raw byte[] body and MessageProperties (headers, content type, delivery tag, reply-to address, correlation id). Converting the bytes to something useful is your job in a plain MessageListener.
A related interface is ChannelAwareMessageListener in org.springframework.amqp.rabbit.listener.api. It adds the RabbitMQ Channel so you can acknowledge or reject messages manually. Do not confuse these with jakarta.jms.MessageListener, which belongs to JMS and is unrelated to RabbitMQ.
A listener container connects to the broker, consumes from one or more queues and invokes your listener. Two containers exist: SimpleMessageListenerContainer, which is the default, and DirectMessageListenerContainer, which invokes the listener directly on the consumer thread.
Then register it on a container bean:
Spring Boot supplies the ConnectionFactory and a RabbitTemplate from the spring.rabbitmq.* properties, and the container starts and stops with the application context.
For application code, an annotated method is shorter and handles conversion:
With Jackson on the classpath and a JacksonJsonMessageConverter or Jackson2JsonMessageConverter bean (the class name depends on your Spring AMQP version), JSON bodies become OrderEvent objects. Boot picks up a MessageConverter bean automatically. Internally, Spring wraps your method in an adapter that implements MessageListener, so both styles share containers, concurrency and error handling.
Use the interface directly when you need the raw bytes and properties, when you build containers programmatically, or when you work with a framework that expects a MessageListener.
These settings decide how safely messages are processed. In Boot they live under spring.rabbitmq.listener.simple.*:
| Property | Meaning |
|---|---|
acknowledge-mode | auto (default), manual or none |
concurrency, max-concurrency | Minimum and maximum consumer threads |
prefetch | How many unacknowledged messages each consumer may hold |
default-requeue-rejected | Whether a failed message is requeued |
retry.enabled | Retry failed deliveries with backoff before giving up |
In auto mode, the container acknowledges after onMessage returns and rejects the message when it throws. If a message always fails and is requeued, it loops forever, a poison message. Prevent that with a dead-letter exchange, a retry limit, or by throwing AmqpRejectAndDontRequeueException for messages that can never succeed.
For manual acknowledgements, implement ChannelAwareMessageListener:
Set the container to AcknowledgeMode.MANUAL for this to take effect.
No. MessageListener is the interface the container calls. @RabbitListener is an annotation that Spring converts into a MessageListener for you, adding message conversion and argument resolution.
No. It runs on a consumer thread owned by the listener container. With concurrency greater than one, several messages can be processed in parallel, so the listener must be thread-safe.
In auto acknowledge mode the container rejects the message. By default it is requeued, so configure retries or a dead-letter queue to avoid an endless redelivery loop.
For RabbitMQ it is org.springframework.amqp.core.MessageListener. JMS has its own jakarta.jms.MessageListener, and Spring Data Redis has org.springframework.data.redis.connection.MessageListener.
MessageListener is the Spring AMQP callback for consuming RabbitMQ messages one at a time via onMessage. Register it on a SimpleMessageListenerContainer or DirectMessageListenerContainer, or let @RabbitListener generate it for you. Pay attention to acknowledgement mode, concurrency and poison-message handling, because those decide whether messages are processed reliably.