Celery trying to connect to wrong broker

5,480

You should add -A option when execute "celery worker" so that celery will connect to the broker you configured in your. Otherwise celery will try to connect the default broker.

Share:
5,480

Related videos on Youtube

user1592380
Author by

user1592380

Updated on September 18, 2022

Comments

  • user1592380
    user1592380 over 1 year

    I have a Django project on an Ubuntu EC2 node, which I have been using to set up an asynchronous using Celery.

    I've been able to get a basic task working at the command line, using:

    (env1)ubuntu@ip-172-31-22-65:~/projects/tp$ celery --app=myproject.celery:app worker --loglevel=INFO
    

    However, if I run other celery commands like below I'm getting the following:

    (env1)ubuntu@ip-172-31-22-65:~/projects/tp$ celery worker

    Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
    

    It appears that celery thinks I'm using amqp as a broker , but I'm using redis!! I've been trying to follow http://michal.karzynski.pl/blog/2014/05/18/setting-up-an-asynchronous-task-queue-for-django-using-celery-redis/

    The installed python packages:

    (env1)ubuntu@ip-172-31-22-65:~/projects/tp$ pip freeze
    amqp==1.4.6
    anyjson==0.3.3
    billiard==3.3.0.19
    celery==3.1.17
    Django==1.7.7
    django-redis-cache==0.13.0
    kombu==3.0.24
    pytz==2015.2
    redis==2.10.3
    requests==2.6.0
    uWSGI==2.0.10
    

    /projects/tp/tp/celery.py

    from __future__ import absolute_import
    
    import os
    import django
    from celery import Celery
    from django.conf import settings
    
    # set the default Django settings module for the 'celery' program.
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings')
    django.setup()
    
    app = Celery('hello_django')
    
    # Using a string here means the worker will not have to
    # pickle the object when using Windows.
    app.config_from_object('django.conf:settings')
    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
    

    also , in redis.conf:

    # Specify the path for the unix socket that will be used to listen for
    # incoming connections. There is no default, so Redis will not listen
    # on a unix socket when not specified.
    #
      unixsocket /var/run/redis/redis.sock
      unixsocketperm 777
    

    tp.settings.py:

    # CELERY SETTINGS
    BROKER_URL = 'redis://localhost:6379/0'
    CELERY_ACCEPT_CONTENT = ['json']
    CELERY_TASK_SERIALIZER = 'json'
    CELERY_RESULT_SERIALIZER = 'json'
    
    CACHES = {
        'default': {
            'BACKEND': 'redis_cache.RedisCache',
            'LOCATION': '/var/run/redis/redis.sock',
        },
    }
    

    How can I get it to use Redis as the broker?

  • Lokesh Tiwari
    Lokesh Tiwari almost 6 years
    Added -A but still not resolved
  • damadam
    damadam almost 6 years
    @LokeshTiwari why don't you ask your proper question?