Spring Boot auto-configures messaging infrastructure for RabbitMQ (AMQP), Apache Kafka, Apache Pulsar, and JMS with ActiveMQ Artemis. Each integration follows the same pattern: set connection properties, autowire a template to produce messages, and annotate listeners to consume them. This guide covers setup, sending, receiving, and transaction configuration for each technology.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
RabbitMQ and Apache Kafka
- RabbitMQ
- Apache Kafka
Connect to RabbitMQ
Add thespring-boot-starter-amqp starter to your project. Configure the broker connection using spring.rabbitmq.* properties:application.yaml
addresses attribute:application.yaml
When
addresses is set, the host and port properties are ignored. If the address uses the amqps protocol, SSL support is enabled automatically.Send messages with RabbitTemplate
AmqpTemplate and AmqpAdmin are auto-configured. Inject AmqpTemplate (backed by RabbitTemplate) directly into your beans:MyBean.java
MessageConverter bean is defined, it is automatically associated with the auto-configured AmqpTemplate.To enable retries when the broker connection is lost:application.yaml
Receive messages with @RabbitListener
Annotate any bean method with@RabbitListener to create a message listener endpoint. A default SimpleRabbitListenerContainerFactory is auto-configured:MyBean.java
spring.rabbitmq.listener.type=direct.Any Queue bean you define is automatically declared on the RabbitMQ instance:MyRabbitConfiguration.java
Apache Pulsar
Add thespring-boot-starter-pulsar starter to your project. Configure the Pulsar client service URL:
application.yaml
PulsarTemplate for producing messages and supports @PulsarListener for consuming messages, following the same pattern as RabbitMQ and Kafka.
JMS with ActiveMQ Artemis
Add thespring-boot-starter-artemis starter to configure JMS with ActiveMQ Artemis. Configure the broker URL and credentials:
application.yaml
JmsTemplate is auto-configured and can be injected directly. Use @JmsListener to create listener endpoints.
If your JMS broker does not support transacted sessions, disable transaction support by customizing the listener container factory:
MyJmsConfiguration.java
This configuration overrides the default factory. Apply the same pattern to any other listener container factories your application defines.
Enable transaction support
Kafka transactions
Kafka transactions
Enable Kafka transactions by setting A custom
spring.kafka.producer.transaction-id-prefix. When this property is set, a KafkaTransactionManager is automatically configured and associated with the listener container factory:application.yaml
ChainedKafkaTransactionManager must be marked @Primary since it usually references the auto-configured KafkaTransactionManager bean.Kafka Streams
Kafka Streams
Enable Kafka Streams by adding the Wire
@EnableKafkaStreams annotation and ensuring kafka-streams is on the classpath. Spring Boot auto-configures the required KafkaStreamsConfiguration bean:application.yaml
StreamsBuilder into your @Bean to define stream processing topology:MyKafkaStreamsConfiguration.java
RabbitMQ retries and dead-letter routing
RabbitMQ retries and dead-letter routing
Enable retries on the When retries are exhausted on the consumer side, the default
AmqpTemplate for producer-side resilience, and configure dead-letter exchange routing on the broker for failed consumer messages:application.yaml
RejectAndDontRequeueRecoverer rejects the message. If the broker has a dead-letter exchange configured, rejected messages are routed there automatically. Define a custom MessageRecoverer bean to override this behavior.Testing with embedded brokers
- Embedded Kafka
- RabbitMQ TestContainers
Annotate a test class with Or configure the property name directly on the annotation:
@EmbeddedKafka from spring-kafka-test to start an embedded Kafka broker. Remap the broker addresses into Spring Boot’s configuration property:application-test.yaml
MyTest.java