7

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://guest@127.0.0.1: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?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
BDuelz
  • 3,890
  • 7
  • 39
  • 62
  • 1
    Looks like celery cannot find your configuration and uses default. Where have you put your `celeryconfig.py` file? It must be on your python path ([docs](http://docs.celeryproject.org/en/latest/configuration.html#configuration-and-defaults)). – alecxe Apr 24 '13 at 07:06

3 Answers3

6

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

DannyMoshe
  • 6,023
  • 4
  • 31
  • 53
Freelancer
  • 4,459
  • 2
  • 22
  • 28
  • 1
    Where would this go? I have a celery.py file which contains similar code as your answer, which is in the same folder as my settings.py. Yet I get same error as OP. Same issue when put in settings.py – Erik Svedin Mar 30 '15 at 13:15
  • I'm having the same problem. Please see my post at http://stackoverflow.com/questions/29402447/how-to-set-celeryconfig-file-in-in-django?noredirect=1#comment47060151_29402447 – user1592380 Apr 04 '15 at 15:45
  • As far as I know `config_from_object` will overwrite `broker` given as argument to the constructor, if `BROKER_URL` exists inside celeryconfig file... – stelios May 29 '17 at 22:55
4

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'
stelios
  • 2,679
  • 5
  • 31
  • 41
0

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!

duhaime
  • 25,611
  • 17
  • 169
  • 224