0
# Spring Boot AMQP Starter
1
2
Spring Boot AMQP Starter provides comprehensive auto-configuration for AMQP (Advanced Message Queuing Protocol) messaging with RabbitMQ. It automatically configures connection factories, rabbit templates, message listeners, and administrative components for robust message-driven applications.
3
4
## Package Information
5
6
- **Package Name**: org.springframework.boot:spring-boot-starter-amqp
7
- **Package Type**: Maven
8
- **Language**: Java
9
- **Installation**: Add to your Maven pom.xml or Gradle build.gradle:
10
11
**Maven:**
12
```xml
13
<dependency>
14
<groupId>org.springframework.boot</groupId>
15
<artifactId>spring-boot-starter-amqp</artifactId>
16
</dependency>
17
```
18
19
**Gradle:**
20
```gradle
21
implementation 'org.springframework.boot:spring-boot-starter-amqp'
22
```
23
24
## Core Imports
25
26
```java
27
import org.springframework.amqp.rabbit.core.RabbitTemplate;
28
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
29
import org.springframework.amqp.core.AmqpAdmin;
30
import org.springframework.amqp.rabbit.annotation.RabbitListener;
31
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
32
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
33
import org.springframework.boot.autoconfigure.amqp.ConnectionFactoryCustomizer;
34
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateCustomizer;
35
```
36
37
## Basic Usage
38
39
```java
40
import org.springframework.amqp.rabbit.core.RabbitTemplate;
41
import org.springframework.amqp.rabbit.annotation.RabbitListener;
42
import org.springframework.beans.factory.annotation.Autowired;
43
import org.springframework.stereotype.Component;
44
45
@Component
46
public class MessageService {
47
48
@Autowired
49
private RabbitTemplate rabbitTemplate;
50
51
// Send messages
52
public void sendMessage(String routingKey, Object message) {
53
rabbitTemplate.convertAndSend(routingKey, message);
54
}
55
56
// Receive messages
57
@RabbitListener(queues = "myQueue")
58
public void handleMessage(String message) {
59
System.out.println("Received: " + message);
60
}
61
}
62
```
63
64
## Architecture
65
66
Spring Boot AMQP Starter is built around several key auto-configuration components:
67
68
- **Connection Management**: Automatically configures `CachingConnectionFactory` with connection pooling and SSL support
69
- **Message Operations**: Provides `RabbitTemplate` and `RabbitMessagingTemplate` for sending/receiving messages
70
- **Administrative Operations**: Auto-configures `AmqpAdmin` for queue, exchange, and binding management
71
- **Listener Infrastructure**: Sets up listener container factories for annotation-driven message consumption
72
- **Property Configuration**: Centralizes all RabbitMQ settings under `spring.rabbitmq` prefix
73
- **Actuator Integration**: Includes health indicators and metrics collection for monitoring
74
75
## Capabilities
76
77
### Core Messaging
78
79
Primary messaging operations using RabbitTemplate and administrative functions through AmqpAdmin. Essential for sending messages, managing queues, and basic RabbitMQ operations.
80
81
```java { .api }
82
// Auto-configured beans available for injection
83
@Autowired RabbitTemplate rabbitTemplate;
84
@Autowired AmqpAdmin amqpAdmin;
85
@Autowired RabbitMessagingTemplate rabbitMessagingTemplate;
86
```
87
88
[Core Messaging](./core-messaging.md)
89
90
### Configuration Properties
91
92
Comprehensive configuration options for RabbitMQ connections, caching, SSL, timeouts, and message handling behavior through `spring.rabbitmq` properties.
93
94
```java { .api }
95
@ConfigurationProperties("spring.rabbitmq")
96
public class RabbitProperties {
97
private String host = "localhost";
98
private Integer port;
99
private String username = "guest";
100
private String password = "guest";
101
// ... many more properties
102
}
103
```
104
105
[Configuration Properties](./configuration.md)
106
107
### Message Listeners
108
109
Annotation-driven message consumption using `@RabbitListener` with auto-configured listener container factories for both simple and direct listening modes.
110
111
```java { .api }
112
@RabbitListener(queues = "queueName")
113
public void handleMessage(String message) { }
114
115
@RabbitListener(bindings = @QueueBinding(
116
value = @Queue("myQueue"),
117
exchange = @Exchange("myExchange"),
118
key = "routing.key"
119
))
120
public void handleMessage(MyObject message) { }
121
```
122
123
[Message Listeners](./listeners.md)
124
125
### Actuator Integration
126
127
Health monitoring and metrics collection for RabbitMQ connections through Spring Boot Actuator endpoints, providing operational visibility into messaging infrastructure.
128
129
```java { .api }
130
// Auto-configured health indicator
131
HealthContributor rabbitHealthContributor;
132
133
// Auto-configured metrics
134
RabbitConnectionFactoryMetricsPostProcessor metricsPostProcessor;
135
```
136
137
[Actuator Integration](./actuator.md)
138
139
### Stream Support
140
141
Auto-configuration for RabbitMQ Streams, a new persistent messaging protocol that provides high-throughput, persistent message streaming capabilities.
142
143
```java { .api }
144
// Auto-configured when RabbitMQ Stream dependencies are available
145
RabbitStreamTemplate rabbitStreamTemplate;
146
```
147
148
[Stream Support](./streams.md)