Last Updated: November 21, 2025
RabbitMQ
Message broker for distributed systems
Core Concepts
| Item | Description |
|---|---|
Exchange
|
Routes messages |
Queue
|
Stores messages |
Binding
|
Links exchange to queue |
Routing Key
|
Message routing attribute |
Producer
|
Sends messages |
Consumer
|
Receives messages |
Acknowledgement
|
Confirm message processed |
Exchange Types
| Item | Description |
|---|---|
Direct
|
Route by exact routing key |
Fanout
|
Broadcast to all queues |
Topic
|
Route by pattern matching |
Headers
|
Route by header attributes |
Node.js Example
const amqp = require('amqplib');
// Publisher
const connection = await amqp.connect('amqp://localhost');
const channel = await connection.createChannel();
await channel.assertQueue('tasks');
channel.sendToQueue('tasks', Buffer.from('Hello'));
// Consumer
channel.consume('tasks', (msg) => {
console.log(msg.content.toString());
channel.ack(msg);
});
Best Practices
- Use acknowledgements for reliability
- Set message TTL to avoid queue bloat
- Use dead letter exchanges for failures
- Monitor queue length and consumer rate
💡 Pro Tips
Quick Reference
Always acknowledge messages after processing