RabbitMQ Python Tutorial: Reliable Order Queues

Resumen

Pixel shares a RabbitMQ tutorial that publishes three shop orders to a real queue using Python and pika. It shows how workers acknowledge successful orders and send a broken message to a dead-letter queue, explaining when durable queues protect important work and when simpler tools may be enough.

DEV Community

RabbitMQ Tutorial: An Order Queue That Never Loses Work

Originally published at https://practicaldevblog.blogspot.com/2026/11/rabbitmq-python-order-queue.html Quick answer RabbitMQ is a message broker: one program puts a message into a queue, and another takes it out later, so slow work does not block the user. This post publishes three shop orders to a real queue with Python and pika, acknowledges the two good ones, and rejects the broken one into a dead-letter queue. It fits work that must survive a crash, and is overkill for a simple in-process job. Picture a small online shop. A customer clicks buy, and the checkout code charges the card and updates stock, all inside one web request. Then the payment gateway stalls, the request times out, the customer clicks buy again, and the card is charged twice. A queue breaks the chain. The web request only has to record the order and hand it to RabbitMQ, and a separate worker takes orders one at a time and confirms each one only when the work is done. If the worker crashes halfway, the order is still in the queue, waiting for the next worker. What I would check before using it My first check: must the work survive a crash? If checkout dies halfway, can someone else pick up the order and finish it? When the answer is yes, a durable queue earns its place. When the answer is no, because the job can simply run again from scratch, a queue is ceremony, and a short list in Redis may do. My second check is who runs the broker. RabbitMQ is one more service to install, watch, and back up. It needs free disk space, and stops accepting messages when the disk fills up. If nobody owns that job, a managed queue from your cloud provider is the honest alternative. My third check is scale. RabbitMQ handles tens of thousands of messages a second on ordinary hardware, enough for most shops and internal tools. It is not the tool for replaying a year of events at massive volume. That is the job Kafka was built for. My fourth check is how failures are handled. Every queue needs an answer for the message that can never be processed: a dead-letter queue to park it in, an alert, and a way to fix and replay it. Without that plan, bad messages vanish silently or loop forever. My verdict, as judgement: adopt RabbitMQ when background work must not be lost, must be retried, and must be spread across workers. Skip it for a single small script or a prototype with no real users. The recommendation flips the moment nobody owns the broker, or the workload turns into an event stream that needs replay. Three orders through a real queue The example is a small shop selling clothes and accessories. Three orders arrive: Ayesha buys a kurta and a dupatta for Rs 12,400, Bilal buys sneakers for Rs 7,800, and Hina buys a handbag and a wallet. Hina's order has a problem: the total was never filled in. That is the kind of bad record that sails through a demo and breaks the first real order. The script connects to a broker on localhost, declares a durable orders queue with a dead-letter exchange for rejects. Each order is published as JSON, persistent with delivery_mode set to 2. The worker takes orders one at a time and acks each one only after charging it. """Order queue demo for The Practical Developer (RabbitMQ, pika).

A small online shop publishes orders to a RabbitMQ queue. A worker
takes them one at a time, charges the customer, and acknowledges each
order. One order arrives without a total, so the worker rejects it and
the broker moves it to a dead-letter queue. A corrected copy of that
order is published and processed cleanly.

Run: python3 rabbitmq_demo.py (RabbitMQ must be listening on localhost:5672)
"""
import json
import pika

QUEUE = "orders"
DLX = "orders_dlx"
DLQ = "orders_dead"

def connect():
connection = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
channel = connection.channel()
channel.exchange_declare(exchange=DLX, exchange_type="fanout", durable=True)
channel.queue_declare(queue=DLQ, durable=True)
channel.queue_bind(exc...
RabbitMQ Python Tutorial: Reliable Order Queues
Powered by Readybot.io

Lo último de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …