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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
2) OPTIONAL – configure a rabbitmq user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ".*" ".*" ".*" |
3) Install Celery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will also install: billiard python-dateutil kombu anyjson amqp | |
sudo pip install Celery | |
# install the Django Celery lib | |
sudo pip install django-celery |
4) Configure your Django application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/' |
5) Sync your DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# when using South | |
python manage.py migrate djcelery | |
# when not using South | |
python manage.py syncdb |
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”