Getting Celery Running with Django, django-celery, RabbitMQ and MacPorts

UPDATE: With the release of Celery 3.1, these instructions are out of date. I’ll be posting some notes on migration and doing a fresh 3.1 installation in the near future.


I recently needed an asynchronous task queue and found the fantastic Celery Project to be just what I was looking for.

Getting up and running was fairly simple as there’s lots of great documentation…

Django + Celery
http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

RabbitMQ
http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html
http://www.rabbitmq.com/install-macports.html

But rather than read all of those, here’s a quick rundown of the 5 steps it takes to get up and running…

1) Install RabbitMQ

# required ports
sudo port install erlang +ssl
sudo port install rabbitmq-server
# start the server on system boot
sudo port load rabbitmq-server
# OPTIONAL – install the librabbitmq C library (it's faster thant the default amqp)
sudo pip install librabbitmq

view raw
installs.sh
hosted with ❤ by GitHub

2) OPTIONAL – configure a rabbitmq user

# RabbitMQ installs with a default username / password of guest / guest
# you can change that by creating a new user
rabbitmqctl add_user myuser mypassword
rabbitmqctl add_vhost myvhost
rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*"

view raw
rabbitmq.sh
hosted with ❤ by GitHub

3) Install Celery

# will also install: billiard python-dateutil kombu anyjson amqp
sudo pip install Celery
# install the Django Celery lib
sudo pip install django-celery

view raw
celery.sh
hosted with ❤ by GitHub

4) Configure your Django application

# add the following to your settings.py
import djcelery
djcelery.setup_loader()
# assuming you didn't change the default RabbitMQ username / password
BROKER_URL = 'amqp://guest:guest@localhost:5672/'

view raw
settings.py
hosted with ❤ by GitHub

5) Sync your DB

# when using South
python manage.py migrate djcelery
# when not using South
python manage.py syncdb

view raw
manage.py
hosted with ❤ by GitHub

Boom goes the dynamite. You can now jump into the beginners Django tutorial found here.

One thought on “Getting Celery Running with Django, django-celery, RabbitMQ and MacPorts”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s