Spring AMQP is the Spring project that wraps the AMQP 0-9-1 protocol, with RabbitMQ as its main broker, in a template-and-listener programming model. It gives you RabbitTemplate for sending, @RabbitListener for receiving, declarative queues, exchanges and bindings, message conversion, and retry and dead-letter handling. You write business methods, and Spring manages connections, channels, threads and acknowledgements.
Spring AMQP is a standalone project with its own release train. It is not part of Spring Integration or Spring Cloud, although both build on it, and Spring Boot auto-configures it through spring-boot-starter-amqp.
Spring AMQP has two modules. spring-amqp holds the broker-neutral abstractions such as Message, Queue, Exchange, Binding and MessageConverter. spring-rabbit implements them for RabbitMQ and adds RabbitTemplate, RabbitAdmin and the listener containers.
Its role in a system is to decouple services. A producer publishes to an exchange and does not know who consumes. Consumers scale out by adding instances that read from the same queue, and a slow consumer does not block the producer.
| Component | Purpose |
|---|---|
RabbitTemplate | Sends messages and performs request-reply calls |
@RabbitListener | Declares a method that consumes from one or more queues |
RabbitAdmin | Declares queues, exchanges and bindings found as beans |
MessageConverter | Converts between Java objects and message bodies, such as JSON |
| Listener container | Manages consumer threads, prefetch, acknowledgements and recovery |
ConnectionFactory | Creates and caches connections and channels |
Listener containers come in two kinds. SimpleMessageListenerContainer uses a dedicated consumer per queue, and DirectMessageListenerContainer invokes listeners directly on the client's consumer threads. The simple container is the default in Spring Boot, and you can change it with spring.rabbitmq.listener.type.
Declare the topology as beans, and RabbitAdmin creates it on the broker when the connection opens. Boot creates the RabbitAdmin for you.
The main queue routes rejected messages to the default exchange with the dead-letter queue name as the routing key. Failed messages therefore end up in orders.created.dlq instead of being lost or looping forever.
Send with RabbitTemplate and receive with @RabbitListener. Registering a JSON MessageConverter bean makes Boot use it for both, so you exchange records instead of raw strings.
Boot detects a single MessageConverter bean and applies it to the template and the listener containers. The class name Jackson2JsonMessageConverter is tied to Jackson 2. Newer Spring AMQP releases that use Jackson 3 provide a replacement class, so check the reference documentation for your version. Restrict which types may be deserialized from the message headers, because accepting arbitrary class names is a security risk.
By default, a listener that throws an exception causes the message to be requeued and redelivered immediately, which can loop forever on a poison message. Configure stateless retry with backoff in application.properties.
After the attempts run out, the message is rejected without requeue and the broker dead-letters it. Use publisher confirms (spring.rabbitmq.publisher-confirm-type=correlated) and publisher returns when losing an outgoing message is not acceptable. Keep listeners idempotent, because redelivery means at-least-once processing.
The abstractions are generic AMQP 0-9-1, but the only maintained implementation is for RabbitMQ. For Kafka use Spring for Apache Kafka, and for RabbitMQ Streams there is a separate integration.
Spring AMQP is the low-level RabbitMQ client abstraction. Spring Cloud Stream is a higher-level binder framework that can sit on RabbitMQ or Kafka and hides broker specifics.
Set spring.rabbitmq.listener.simple.concurrency and max-concurrency, or concurrency on @RabbitListener. Ordering is then guaranteed only within a single consumer.
No. You can create topology with broker definitions or infrastructure tooling. Declaring beans is convenient for development and small services.
Spring AMQP gives Spring applications a clean, declarative way to use RabbitMQ. RabbitTemplate publishes, @RabbitListener consumes, beans define the topology, converters handle payloads, and listener containers manage concurrency and acknowledgements. Add retry with a dead-letter queue, keep handlers idempotent, and use publisher confirms where delivery matters.