Spring AMQP in a Spring Boot service

RabbitMQ Course · lesson 13 of 15 · 5 min read

The starter wires everything, and the one default that surprises people is what AUTO means.

Open this lesson in the learning hub

Key points

  • spring-boot-starter-amqp auto-configures a ConnectionFactory, RabbitTemplate and RabbitAdmin.
  • Any Queue, Exchange or Binding bean is declared on the broker at startup by RabbitAdmin.
  • AcknowledgeMode.AUTO is the default and does not mean AMQP auto-ack - the container acks for you.
  • AcknowledgeMode.NONE is 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.