A minimal Celery app using CloudAMQP, or any AMQP 0-9-1 broker such as LavinMQ or RabbitMQ, as the broker.
celeryconfig.pyhas the settings we recommend for CloudAMQP, explained in the CloudAMQP Celery docs.tasks.pydefines ahellotask.publisher.pysends it to the worker.
Tool versions are in mise.toml; with mise a virtualenv
is created in .venv automatically. Otherwise use Python 3.9+ and a virtualenv.
pip install -r requirements.txt
export BROKER_URL="amqps://user:password@host/vhost"
celery -A tasks worker --without-heartbeat --without-gossip --without-mingle # in one terminal
python publisher.py # in anotherThe --without-* flags stop the worker from sending heartbeat, gossip and
mingle messages, which otherwise add up to hundreds of messages per second.
Without BROKER_URL it connects to amqp://guest:guest@localhost.
pytest starts an embedded worker with the settings in celeryconfig.py, and
runs a task through a real broker on localhost. CI runs it against LavinMQ.
pip install -r requirements-dev.txt
pytest