Skip to main content

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.

Spring Boot provides first-class support for a wide variety of messaging systems through dedicated auto-configuration starters. Whether you need point-to-point queues, publish-subscribe topics, or streaming event logs, Spring Boot configures the required connection factories, templates, and listener containers so you can focus on message handling logic rather than infrastructure setup.

RabbitMQ / AMQP

spring-boot-starter-amqp — Lightweight, reliable message broker with rich routing via exchanges and queues.

Apache Kafka

spring-boot-starter-kafka — High-throughput distributed event streaming for real-time data pipelines.

Apache Pulsar

spring-boot-starter-pulsar — Cloud-native messaging with multi-tenancy, geo-replication, and tiered storage.

JMS

spring-boot-starter-activemq / spring-boot-starter-artemis — Java Message Service with embedded broker support.

RabbitMQ (AMQP)

The Advanced Message Queuing Protocol (AMQP) is a platform-neutral, wire-level protocol for message-oriented middleware. Spring Boot offers several conveniences for working with AMQP through RabbitMQ, including auto-configured AmqpTemplate and AmqpAdmin beans. Configuration:
application.yaml
spring:
  rabbitmq:
    host: "localhost"
    port: 5672
    username: "admin"
    password: "secret"
Alternatively, use the addresses attribute:
application.yaml
spring:
  rabbitmq:
    addresses: "amqp://admin:secret@localhost"
Sending messages: Spring’s AmqpTemplate and AmqpAdmin are auto-configured and can be autowired directly into your beans:
MyBean.java
@Component
public class MyBean {

    private final AmqpTemplate amqpTemplate;

    public MyBean(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }

    public void send(String message) {
        amqpTemplate.convertAndSend("myExchange", "myRoutingKey", message);
    }
}
Enable retries for transient connection failures:
application.yaml
spring:
  rabbitmq:
    template:
      retry:
        enabled: true
        initial-interval: "2s"
Receiving messages with @RabbitListener:
MyBean.java
@Component
public class MyBean {

    @RabbitListener(queues = "someQueue")
    public void processMessage(String content) {
        // handle message
    }
}
By default, if retries are disabled and the listener throws an exception, the delivery is retried indefinitely. Set defaultRequeueRejected to false or throw AmqpRejectAndDontRequeueException to prevent infinite redelivery.

Apache Kafka

Apache Kafka is supported by providing auto-configuration of the spring-kafka project. Kafka configuration is controlled by external configuration properties in spring.kafka.*. Configuration:
application.yaml
spring:
  kafka:
    bootstrap-servers: "localhost:9092"
    consumer:
      group-id: "myGroup"
Sending messages with KafkaTemplate:
MyBean.java
@Component
public class MyBean {

    private final KafkaTemplate<String, String> kafkaTemplate;

    public MyBean(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    public void send(String message) {
        kafkaTemplate.send("someTopic", message);
    }
}
Receiving messages with @KafkaListener:
MyBean.java
@Component
public class MyBean {

    @KafkaListener(topics = "someTopic")
    public void processMessage(String content) {
        // handle message
    }
}
To create a topic on startup, add a bean of type NewTopic. If the topic already exists, the bean is ignored.
Kafka Streams: Spring Boot auto-configures the required KafkaStreamsConfiguration bean as long as kafka-streams is on the classpath and Kafka Streams is enabled with @EnableKafkaStreams:
MyKafkaStreamsConfiguration.java
@Configuration
@EnableKafkaStreams
public class MyKafkaStreamsConfiguration {

    @Bean
    public KStream<String, String> wordCountStream(StreamsBuilder streamsBuilder) {
        KStream<String, String> stream = streamsBuilder.stream("input-topic");
        stream
            .flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))
            .groupBy((key, word) -> word)
            .count(Materialized.as("word-count"))
            .toStream()
            .to("output-topic", Produced.with(Serdes.String(), Serdes.Long()));
        return stream;
    }
}
Additional Kafka properties: For properties not directly supported through KafkaProperties, use the nested properties namespace:
application.yaml
spring:
  kafka:
    properties:
      "[prop.one]": "first"
    consumer:
      properties:
        "[prop.three]": "third"
    producer:
      properties:
        "[prop.four]": "fourth"

Apache Pulsar

Apache Pulsar is supported by providing auto-configuration of the Spring for Apache Pulsar project. Starter: spring-boot-starter-pulsar Connection configuration:
application.yaml
spring:
  pulsar:
    client:
      service-url: "pulsar://localhost:6650"
Sending messages with PulsarTemplate:
MyBean.java
@Component
public class MyBean {

    private final PulsarTemplate<String> pulsarTemplate;

    public MyBean(PulsarTemplate<String> pulsarTemplate) {
        this.pulsarTemplate = pulsarTemplate;
    }

    public void send(String message) throws PulsarClientException {
        pulsarTemplate.send("someTopic", message);
    }
}
Receiving messages with @PulsarListener:
MyBean.java
@Component
public class MyBean {

    @PulsarListener(topics = "someTopic")
    public void processMessage(String content) {
        // handle message
    }
}
Reading messages with @PulsarReader:
MyBean.java
@Component
public class MyBean {

    @PulsarReader(topics = "someTopic", startMessageId = "earliest")
    public void readMessage(String content) {
        // process message
    }
}
Enable Pulsar transactions:
application.yaml
spring:
  pulsar:
    transaction:
      enabled: true
Authentication configuration:
application.yaml
spring:
  pulsar:
    client:
      authentication:
        plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2
        param:
          issuerUrl: https://auth.server.cloud/
          privateKey: file:///Users/some-key.json
          audience: urn:sn:acme:dev:my-instance

JMS

When spring-boot-starter-activemq is on the classpath, Spring Boot auto-configures a ConnectionFactory. An embedded broker starts automatically if no broker URL is specified.
application.yaml
spring:
  activemq:
    broker-url: "tcp://192.168.1.210:9876"
    user: "admin"
    password: "secret"
Disable the embedded broker explicitly:
application.yaml
spring:
  activemq:
    embedded:
      enabled: false
Sending messages with JmsClient:
MyBean.java
@Component
public class MyBean {

    private final JmsClient jmsClient;

    public MyBean(JmsClient jmsClient) {
        this.jmsClient = jmsClient;
    }

    public void send(String message) {
        jmsClient.createSend().destination("someQueue").body(message).send();
    }
}
Receiving messages with @JmsListener:
MyBean.java
@Component
public class MyBean {

    @JmsListener(destination = "someQueue")
    public void processMessage(String content) {
        // handle message
    }
}

Spring Integration

Spring Integration provides a framework for building message-driven architectures based on enterprise integration patterns. Spring Boot provides auto-configuration and a starter for Spring Integration:
pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-integration</artifactId>
</dependency>
Spring Boot auto-configures the SpringIntegration management infrastructure. If spring-integration-jmx is also on the classpath, message processing statistics are published via JMX.

WebSockets

Add the WebSocket starter to enable WebSocket support:
pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
For Spring GraphQL WebSocket subscriptions, set the WebSocket path:
application.yaml
spring:
  graphql:
    websocket:
      path: "/graphql-ws"
For WebFlux applications, GraphQL WebSocket support requires no additional dependency beyond spring-boot-starter-webflux.

Build docs developers (and LLMs) love