BDuelz
BDuelz

Reputation: 3928

Celery tries to connect to the wrong broker

I have in my celery configuration

BROKER_URL = 'redis://127.0.0.1:6379'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379'

Yet whenever I run the celeryd, I get this error

consumer: Cannot connect to amqp://[email protected]:5672//: [Errno 111] Connection refused. Trying again in 2.00 seconds...

Why is it not connecting to the redis broker I set it up with, which is running btw?

Upvotes: 7

Views: 12143

Answers (3)

Freelancer
Freelancer

Reputation: 4770

import your celery and add your broker like that :

celery = Celery('task', broker='redis://127.0.0.1:6379')
celery.config_from_object(celeryconfig)

This code belongs in celery.py

Upvotes: 6

duhaime
duhaime

Reputation: 27594

I got this response because I was starting my celery worker incorrectly on the terminal.

I was running:

celery -A celery worker

But because I defined celery inside of web/server.py, I needed to run:

celery -A web.server.celery worker

web.server indicates that my celery object is in a file server.py inside a directory web. Running that latter command connected to the broker I specified!

Upvotes: 0

stelios
stelios

Reputation: 2845

If you followed First Steps with Celery tutorial, specifically:

app.config_from_object('django.conf:settings', namespace='CELERY')

then you need to prefix your settings with CELERY, so change your BROKER_URL to:

CELERY_BROKER_URL = 'redis://127.0.0.1:6379'

Upvotes: 4

Related Questions