Setting Up Celery with a Broker
Wire Celery to Redis or RabbitMQ.
Setting Up Celery with a Broker is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What a Broker Is
Celery needs a broker: a middleman that holds queued tasks until a worker grabs them. Think of it as the inbox between your app and the workers.
Redis or RabbitMQ
The two common brokers are Redis (simple, fast, great default) and RabbitMQ (heavier, very robust). For most Django apps, Redis is plenty. 📨
Install the Packages
Start by installing Celery and the Redis client so Celery can talk to your broker over the network.
pip install celery redisCreate the Celery App
Add a celery.py next to settings.py. It creates the Celery instance and tells it where to find your Django config.
import os
from celery import Celery
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
app = Celery("myproject")Read Config from Settings
Point Celery at your Django settings so all its options live in one place, namespaced with a CELERY prefix.
app.config_from_object("django.conf:settings", namespace="CELERY")Auto-Discover Tasks
One line tells Celery to scan every installed app for a tasks module, so you never have to register tasks by hand.
app.autodiscover_tasks()Wire It into __init__
In your project __init__.py, import the Celery app so it loads whenever Django starts. This makes the shared task decorator work.
from .celery import app as celery_app
__all__ = ("celery_app",)Set the Broker URL
In settings.py, point CELERY_BROKER_URL at your running Redis instance so producers and workers share the same queue.
CELERY_BROKER_URL = "redis://localhost:6379/0"Add a Result Backend
If you want to read task results later, set a result backend. Redis can serve double duty as both broker and result store.
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"Start a Worker
Run the worker from a terminal. It connects to the broker and waits for jobs. Keep your Django server running in a separate terminal. 🛠️
celery -A myproject worker -l infoTwo Processes, Always
Remember: the web server and the worker are separate processes. Both must run for background tasks to actually execute.
Quick Check
What job does the broker do in a Celery setup?
Recap: Celery Setup
Install Celery and a broker like Redis, create celery.py, set the broker URL, and run a worker in its own terminal. You are ready to queue. ✅
Frequently asked questions
Is the “Setting Up Celery with a Broker” lesson free?
Yes — the full text of “Setting Up Celery with a Broker” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “Setting Up Celery with a Broker”?
Wire Celery to Redis or RabbitMQ. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Setting Up Celery with a Broker” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why You Need Background Tasks
- Setting Up Celery with a Broker
- Writing and Calling @shared_task
- Scheduled Jobs with Celery Beat