The spring-boot-starter-amqp dependency adds Spring AMQP and its Spring Boot auto-configuration, which lets your application send and receive messages through RabbitMQ with very little code. It gives you a configured connection, a RabbitTemplate for sending, @RabbitListener for receiving and an AmqpAdmin for declaring queues and exchanges.
AMQP 0-9-1 is the protocol RabbitMQ speaks, and the starter is built around it. Use it to move work out of the request thread, decouple services and absorb traffic spikes.
The starter pulls in spring-rabbit (Spring AMQP) and the RabbitMQ Java client. Spring Boot then auto-configures these beans when a RabbitMQ connection is available:
| Bean | Role |
|---|---|
CachingConnectionFactory | Opens and caches connections and channels to the broker |
RabbitTemplate | Sends messages and can do request/reply |
RabbitAdmin (AmqpAdmin) | Declares queues, exchanges and bindings found in the context |
SimpleRabbitListenerContainerFactory | Creates listener containers for @RabbitListener methods |
RabbitMessagingTemplate | Spring messaging flavour of the template |
Spring AMQP targets the AMQP 0-9-1 protocol used by RabbitMQ, so in practice this starter means RabbitMQ.
Configure the broker connection in application.properties:
Do not ship the default guest account. RabbitMQ only allows guest from localhost, and real deployments need their own user. Read secrets from environment variables or a secrets manager rather than committing them.
For local development you can start a broker with Docker:
The management UI is then at http://localhost:15672.
Declare the topology as beans, and RabbitAdmin creates it on the broker when the connection opens:
A durable queue survives a broker restart. If a queue already exists with different arguments, the declaration fails, so change settings deliberately.
A producer injects RabbitTemplate:
A consumer is a method annotated with @RabbitListener:
Calling publish("A-1001") prints this on the consumer:
The default converter handles strings and byte arrays. To send objects such as Java records as JSON, register a JSON message converter bean; Spring Boot picks up a single MessageConverter bean and applies it to the template and listeners. The class name differs between Spring AMQP versions, so check the documentation of your version.
Messaging without failure handling loses or duplicates messages. These settings cover the most common cases:
QueueBuilder.durable(QUEUE).deadLetterExchange("orders.dlx")) so poison messages are kept for inspection.Messaging gives asynchronous processing, loose coupling, load levelling and horizontal scaling by adding consumers to a queue. It also adds operational cost: you must run and monitor a broker, handle duplicates and design for eventual consistency. For a simple in-process background task, @Async or a scheduled job is often enough. For event streaming with replay, a log-based system such as Kafka may fit better.
In practice yes. It is built on Spring AMQP, which targets AMQP 0-9-1 and is mainly used with RabbitMQ.
RabbitTemplate sends messages (and can receive synchronously). @RabbitListener registers a method that is invoked asynchronously whenever a message arrives on a queue.
No. You can create them in the RabbitMQ UI, but declaring them as beans keeps the topology versioned with the application.
Disable requeueing with default-requeue-rejected=false, enable limited retries and route failures to a dead-letter queue.
The spring-boot-starter-amqp dependency auto-configures a RabbitMQ connection, RabbitTemplate, RabbitAdmin and listener containers. Declare queues and exchanges as beans, send with convertAndSend, receive with @RabbitListener, and add retries, dead-letter queues and idempotent consumers for reliable production messaging.