Python Django Celery - 无法连接到 amqp://[email protected]:5672//

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18133249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:57:46  来源:igfitidea点击:

Django Celery - Cannot connect to amqp://[email protected]:5672//

pythondjangocelery

提问by IdeoREX

I'm trying to set up Django-Celery. I'm going through the tutorial

我正在尝试设置 Django-Celery。我正在学习教程

http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

when I run $ python manage.py celery worker --loglevel=info

当我运行 $ python manage.py celery worker --loglevel=info

I get

我得到

[Tasks]


/Users/msmith/Documents/dj/venv/lib/python2.7/site-packages/djcelery/loaders.py:133:     UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in     production environments!
warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2013-08-08 11:15:25,368: WARNING/MainProcess] /Users/msmith/Documents/dj/venv/lib/python2.7/site-packages/djcelery/loaders.py:133: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2013-08-08 11:15:25,369: WARNING/MainProcess] celery@sfo-mpmgr ready.
[2013-08-08 11:15:25,382: ERROR/MainProcess] consumer: Cannot connect to     amqp://[email protected]:5672/celeryvhost: [Errno 61] Connection refused.
Trying again in 2.00 seconds...

has anyone encountered this issue before?

有没有人遇到过这个问题?

settings.py

设置.py

# Django settings for summertime project.
import djcelery
djcelery.setup_loader()

BROKER_URL = 'amqp://guest:guest@localhost:5672/'

...

INSTALLED_APPS = {
    ...
    'djcelery',
    'celerytest'
}

wsgi.py

wsgi.py

import djcelery
djcelery.setup_loader()

采纳答案by geekazoid

The problem is that you are trying to connect to a local instance of RabbitMQ. Look at this line in your settings.py

问题是您正在尝试连接到 RabbitMQ 的本地实例。看看你的这一行settings.py

BROKER_URL = 'amqp://guest:guest@localhost:5672/'

If you are working currently on development, you could avoid setting up Rabbit and all the mess around it, and just use a development version of a message queue with the Django database.

如果您目前正在进行开发,则可以避免设置 Rabbit 及其周围的所有混乱,而只需使用带有 Django 数据库的消息队列的开发版本。

Do this by replacing your previous configuration with:

通过将您以前的配置替换为:

BROKER_URL = 'django://'

...and add this app:

...并添加此应用程序:

INSTALLED_APPS += ('kombu.transport.django', )

Finally, launch the worker with:

最后,使用以下命令启动工作程序:

./manage.py celery worker --loglevel=info

Source: http://docs.celeryproject.org/en/latest/getting-started/brokers/django.html

来源:http: //docs.celeryproject.org/en/latest/getting-started/brokers/django.html

回答by jatin

If you are workling on a production environment,

如果您在生产环境中工作,

You have to first install and setup a rabbitmq server. You can refer rabbitmq website for installation steps.

您必须首先安装和设置rabbitmq 服务器。您可以参考 rabbitmq 网站了解安装步骤。

In settings you have to write this lines:

在设置中,您必须编写以下行:

CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
BROKER_URL = 'amqp://guest:guest@localhost:5672//'

After all setup of rabitmq server you have to run this two command,

在 rabitmq 服务器的所有设置之后,您必须运行这两个命令,

export C_FORCE_ROOT='true'
celery -A transcoder(name of app) worker --loglevel=info

回答by xiaolin

I got this error because rabbitmqwas not started. If you installed rabbitmqvia brew you can start it using brew services start rabbitmq

我收到此错误是因为rabbitmq未启动。如果您rabbitmq通过 brew安装,则可以使用brew services start rabbitmq