About spring-amqp
A quick-reference skill for using Spring AMQP with RabbitMQ in Spring applications. It guides developers through broker configuration, message production and consumption, reliability practices, and troubleshooting.
Key features
- 01Spring AMQP dependency and configuration
- 02Exchange, queue, and binding setup
- 03Message producer and consumer examples
- 04Acknowledgment and dead-letter guidance
- 05Retry and troubleshooting guidance
Use cases
- 01Adding RabbitMQ messaging to a Spring application
- 02Configuring order-event producers and consumers
- 03Investigating message delivery or serialization failures
MCP support
The skill references `mcp__documentation__fetch_docs` to retrieve comprehensive RabbitMQ documentation.
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ claude-dev-suite/ claude-dev-suite --skill spring-amqpAfter installing, type/spring-amqpin Claude Code to confirm it loaded.
Bundled filesadvanced.md
Details
From the project READMESpring AMQP (RabbitMQ) - Quick Reference
Full Reference: See advanced.md for exchange types (topic, fanout), consumer patterns (multi-method, request-reply), error handling, DLQ processing, and testing.
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:rabbitmqfor comprehensive documentation.
Dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
Configuration
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
listener:
simple:
acknowledge-mode: manual
concurrency: 3
max-concurrency: 10
prefetch: 10
Exchange, Queue, Binding Setup
@Configuration
public class RabbitMQConfig {
public static final String EXCHANGE = "orders.exchange";
public static final String QUEUE = "orders.queue";
public static final String ROUTING_KEY = "orders.created";
@Bean
public DirectExchange ordersExchange() {
return new DirectExchange(EXCHANGE);
}
@Bean
public Queue ordersQueue() {
return QueueBuilder.durable(QUEUE)
.withArgument("x-dead-letter-exchange", "orders.dlx")
.withArgument("x-dead-letter-routing-key", "dead")
.build();
}
@Bean
public Binding ordersBinding() {
return BindingBuilder.bind(ordersQueue()).to(ordersExchange()).with(ROUTING_KEY);
}
@Bean
public Jackson2JsonMessageConverter messageConverter() {
return new Jackson2JsonMessageConverter();
}
}
Producer
@Service
@RequiredArgsConstructor
public class OrderProducer {
private final RabbitTemplate rabbitTemplate;
public void sendOrder(OrderEvent event) {
rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, event);
}
public void sendWithHeaders(OrderEvent event, String correlationId) {
rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, event, message -> {
message.getMessageProperties().setCorrelationId(correlationId);
message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
return message;
});
}
}
Consumer
@Service
public class OrderConsumer {
@RabbitListener(queues = "orders.queue")
public void consume(
@Payload OrderEvent event,
@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
@Header(AmqpHeaders.CORRELATION_ID) String correlationId,
Channel channel) throws IOException {
try {
processOrder(event);
channel.basicAck(deliveryTag, false);
} catch (Exception e) {
channel.basicNack(deliveryTag, false, false); // Send to DLQ
}
}
}
Best Practices
| Do | Don't |
|---|---|
| Use manual acknowledgment | Auto-ack without processing |
| Configure DLX/DLQ | Silently lose failed messages |
| Set message TTL | Keep messages forever |
| Use persistent delivery | Transient for important messages |
| Configure prefetch | Unbounded prefetch |
When NOT to Use This Skill
- Raw RabbitMQ - Use
rabbitmqskill for server configuration - Kafka integration - Use
spring-kafkaskill - Generic messaging patterns - Consult
messaging-expert
Anti-Patterns
| Anti-Pattern | Problem | Solution |
|---|---|---|
| Auto-ack without processing | Message loss | Use manual acknowledgment |
| No DLQ configured | Lost failed messages | Configure dead letter exchange |
| Unbounded prefetch | Memory issues | Set appropriate prefetch count |
| Blocking in listener | Thread exhaustion | Use async processing |
| No retry policy | Temporary failures cause loss | Configure retry with backoff |
Quick Troubleshooting
| Problem | Diagnostic | Fix |
|---|---|---|
| Connection refused | Check RabbitMQ running | Verify host/port |
| Message not consumed | Check queue binding | Verify routing key |
| Messages in DLQ | Check x-death header | Fix processing error |
| Consumer not starting | Check @RabbitListener | Verify queue exists |
| Serialization error | Check message type | Configure Jackson converter |
Production Checklist
- Connection factory configured
- Manual acknowledgment mode
- DLX/DLQ configured
- Retry policy set
- Message converter configured
- Publisher confirms enabled
- Prefetch count optimized
- Error handler implemented
- Message TTL set
- Monitoring enabled
Reference Documentation
Comments
Markdown supported