Junior — Middle
Can you explain the main differences between the backend and broker parameters in Celery?
sobes.tech AI
Answer from AI
In Celery, the parameters backend and broker are responsible for different aspects of the system's operation:
-
broker — is an intermediary for message passing between the client and workers. It manages the task queue. Usually, this is RabbitMQ, Redis, or another message broker. The client sends a task to the broker, and workers retrieve tasks from the broker for execution.
-
backend — is a system for storing the results of task execution. After a task is completed, its result is saved in the backend so that the client can retrieve it later. Databases, Redis, RPC, and others can be used as backends.
Example configuration:
app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/1')
Here, Redis is used both as a broker and as a backend, but on different databases (0 and 1).