Celery + rabbitmq in result backend
15,432
You should not use Celery('tasks', broker='amqp://[email protected]//')
along with your celeryconfig.py file.
The way you should go (and the way of the documentation) is:
Create a package called mypackage (it is assumed that mypackage is not a sub package) with two files:
celery.py
from __future__ import absolute_import
from celery import Celery
app = Celery('mypackage',
broker='amqp://[email protected]//',
backend='amqp://[email protected]//',
include=['mypackage.tasks'] #References your tasks. Donc forget to put the whole absolute path.
)
app.conf.update(
CELERY_TASK_SERIALIZER = 'json',
CELERY_RESULT_SERIALIZER = 'json',
CELERY_ACCEPT_CONTENT=['json'],
CELERY_TIMEZONE = 'Europe/Oslo',
CELERY_ENABLE_UTC = True
)
tasks.py
from mypackage.celery import app
@app.task
def add(x, y):
return x + y
Your call.py file is fine.
Start the Celery worker by using celery -A mypackage worker
in command line, in the parent directory of mypackage.
Then you can start another Python interpreter, use call.py and voila!
Related videos on Youtube

Author by
Leon
Updated on June 04, 2022Comments
-
Leon 7 months
tasks.py:
from celery import Celery app = Celery('tasks', broker='amqp://[email protected]//') @app.task def add(x, y): return x + y
call.py:
from tasks import add result = add.delay(1, 4) result.ready()
celeryconfig.py: (in the same directory)
BROKER_URL = 'amqp://[email protected]//' CELERY_RESULT_BACKEND = 'amqp://[email protected]//' CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' CELERY_ACCEPT_CONTENT=['json'] CELERY_TIMEZONE = 'Europe/Oslo' CELERY_ENABLE_UTC = True
In call.py I have en error:
AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
I read the docs, I have result backend, why it does not work? How to fix that?
Thanks!
-
chachan over 7 yearsI'm looking for how to use Rabbit as both broker and backend but I found in the docs that it shouldn't use amqp. docs
-
Amichai Schreiber almost 6 years@chachan that link is broken - can you elaborate?
-
chachan almost 6 years@AmichaiSchreiber you're right. I don't see it anymore. Sorry