Testing the installation
Let's try a quick example to make sure that our Celery installation is working. We will need four terminal windows on, ideally, three different machines (again, we will call them HOST1
, HOST2
, HOST3
, and HOST4
). We will start RabbitMQ in one window on HOST1
, as shown in the following command (make sure that you use the correct path to rabbitmq-server
):
HOST1 $ sudo /usr/local/sbin/rabbitmq-server
In another terminal window (on HOST2
), start Redis (if you did not install it, skip to the next paragraph) as follows (make sure to use the correct path to redis-server
):
HOST2 $ sudo /usr/local/bin/redis-server
Finally, in a third window (HOST3
), create the following Python script (always remember to activate our virtual environment using workon book
) and call it test.py
:
import celery app = celery.Celery('test', broker='amqp://HOST1', backend='redis://HOST2') @app.task def echo(message): return message
What this code...