Spring AMQP in a Spring Boot service
The starter wires everything, and the one default that surprises people is what AUTO means.
Open this lesson in the learning hubKey points
spring-boot-starter-amqpauto-configures a ConnectionFactory, RabbitTemplate and RabbitAdmin.- Any Queue, Exchange or Binding bean is declared on the broker at startup by RabbitAdmin.
AcknowledgeMode.AUTOis the default and does not mean AMQP auto-ack - the container acks for you.AcknowledgeMode.NONEis the one that switches on broker auto-ack and can silently lose messages.- Defaults worth knowing: prefetch 250, default-requeue-rejected true, publisher-confirm-type none.
- Register a Jackson2JsonMessageConverter so payloads travel as JSON rather than Java serialization.
Example
@Configuration
class OrderMessaging {
@Bean TopicExchange orders() { return new TopicExchange("orders", true, false); }
@Bean Queue invoicing() {
return QueueBuilder.durable("invoicing")
.deadLetterExchange("orders.dlx")
.quorum()
.build();
}
@Bean Binding b(Queue invoicing, TopicExchange orders) {
return BindingBuilder.bind(invoicing).to(orders).with("order.created");
}
@Bean MessageConverter json() { return new Jackson2JsonMessageConverter(); }
}
@Component
class InvoiceListener {
@RabbitListener(queues = "invoicing")
void on(OrderCreated event) { // throwing rejects the message
invoiceService.create(event); // container acks on clean return
}
}
Leave acknowledge-mode on AUTO and set default-requeue-rejected to false - that pair is the safe baseline.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the RabbitMQ Course course, and every lesson in it is listed on the RabbitMQ Course contents page.