Handling time-consuming tasks asynchronously improves web application performance and responsiveness. Django integrates with Celery to manage asynchronous and scheduled tasks, enabling background execution and scheduling. A message broker such as Redis, RabbitMQ, or Amazon SQS is required to queue tasks and mediate communication between the Django app and Celery workers. Workers run in background processes that execute tasks and return results through the broker. Celery installation supports broker-specific extras and can be installed with pip or poetry using syntax like celery[redis], celery[rabbitmq], or celery[sqs]. Broker installations require additional dependencies documented in Celery's backends and brokers documentation.
A Celery broker is a message queue that Celery uses to communicate with workers. Workers are processes that run in the background and execute tasks. When you send a task to a Celery broker, the broker will send the task to a worker that is available to execute it. In other words, a Celery broker acts like a middleman or a bridge that connects your Django app to Celery workers. It sends tasks to workers and then returns the results back to your Django app.
Install Celery using pip: pip install celery[redis] Install Celery using poetry: poetry add celery[redis] Note that, The [redis] part is an extra specifier that installs the necessary Redis broker dependencies along with Celery. If you prefer using other popular brokers such as RabbitMQ or Amazon SQS, you can modify the command accordingly. For example, to use RabbitMQ: pip install celery[rabbitmq] # or with poetry poetry add celery[rabbitmq] For Amazon SQS: pip install celery[sqs] # or with poetry poetry add celery[sqs]
Collection
[
|
...
]