Advantage of Queue
- decoupling:
- Scalable : Multiple comnsuming Service
- Performeant : Queue Can sit on its own machine
- Cloud Friendly
- Cross language communication(Python,Java,C#)
- Message Acknowledgemnet
- Broser based management
- Plug -INS
Check out service is connected to Exchange and exchange is connected to queue by binding keys.. Consumers are subscribed to the queue
- Fanout exchange: All the meesage to exchange will be duplicated and passed to all the queues.
- Direct Exchage : In this exchange the producer will produce the message and that message will also produce the routing key, The routing key is then compared to the binding key of queue, If exact match then it is moved the queue accordingly.
- Topic excahnge : Partial match between routing key and binding key, If routing key is"ship.shoes" and binding key is "ship.any", and exchnage is topic excahneg then it will routed to the queue
- Header Exchange: Roting key is ignored, the message is moved to the ssytem accroding to the header
- Default Exchange: Routing key is tied to the name of queue itself
- RabbitMQ: Message broker for asynchronous communication.
- Producer → Exchange → Queue → Consumer
- Implements AMQP protocol.
- Decouples services, improves reliability, fault tolerance, and scalability.
| Component | Role |
|---|---|
| Producer | Sends messages |
| Exchange | Routes messages (direct, fanout, topic, headers) |
| Queue | Stores messages |
| Consumer | Receives messages |
| Binding | Connects Exchange → Queue with rules |
- Direct → exact routing key match
- Fanout → broadcasts to all queues (routing key ignored)
- Topic → pattern-based routing with
*and#wildcards - Headers → routing based on message headers
- ACK → consumer confirms successful processing → message deleted
- NACK / Reject → consumer failed → can requeue or move to DLQ
- No ACK / crash → message requeued automatically
- Use manual ACK (
noAck: false) for reliability
-
DLQ: queue for failed/unprocessed messages
-
DLX: exchange that routes failed messages to DLQ
-
Messages go to DLQ if:
- NACK with
requeue=false - TTL expires
- Queue length exceeded
- NACK with
-
RabbitMQ does NOT auto-send unacked messages to DLQ
-
Retry count is infinite by default; use
x-deathheader + retry queues for limited retries
- Message TTL → expires if not consumed within given time
- Configurable at queue-level (
x-message-ttl) or per-message (expiration) - Expired messages can go to DLQ via DLX
- RabbitMQ has no native ACK timeout; must implement with retry queues or consumer logic
- Ignores routing key
- Broadcasts every message to all queues bound to it
- Each queue receives a copy of the message
- Common for logs, notifications, audit events
- RabbitMQ messages are binary → Node.js requires
Buffer Buffer.from(string)converts string → bytes- Consumer reads with
msg.content.toString() - Works for JSON, strings, or raw bytes
-
Default retry → infinite (message requeued if unacked)
-
Controlled retry → use:
- Retry queue with TTL
x-deathheader to track retry count- NACK with
requeue=false→ DLQ after max retries
- DLX is always an exchange — can be direct, fanout, topic, headers.
- Messages only go to DLQ via NACK/TTL/queue limits, not just missing ACK.
- Fanout = broadcast; Topic = pattern-based; Direct = exact match.
- Manual ACK is essential for reliability.
- TTL + DLQ + retry queues = production-grade setup.
If you want, I can also make a single visual diagram showing the entire flow: producer → exchanges → queues → retries → DLQ — covering fanout, topic, TTL, ACK/NACK all in one shot.
Do you want me to do that?