55

我正在尝试设置 Django-Celery。我正在阅读教程

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

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

我明白了

[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://guest@127.0.0.1:5672/celeryvhost: [Errno 61] Connection refused.
Trying again in 2.00 seconds...

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

设置.py

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

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

...

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

wsgi.py

import djcelery
djcelery.setup_loader()
4

8 回答 8

33

Update Jan 2022: This answer is outdated. As suggested in comments, please refer to this link

The problem is that you are trying to connect to a local instance of RabbitMQ. Look at this line in your 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.

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

于 2013-12-16T17:55:22.217 回答
23

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

于 2016-10-20T14:32:55.200 回答
9

您可以将这些行添加到您的 settings.py :

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'

并运行:

celery -A yourProjectName worker -l info
于 2021-04-18T15:00:58.500 回答
4

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

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

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

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

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

export C_FORCE_ROOT='true'
celery -A transcoder(name of app) worker --loglevel=info
于 2014-12-20T10:11:50.737 回答
0

如果上述所有解决方案都不起作用,您可以尝试以下方法: turn off your network connection (wifi or wire).

这很奇怪,但有时它对我有用!

似乎它与本地网络设备而不是 RabbitMQ 服务有关。

我的屏幕录制:https ://drive.google.com/file/d/13t35Lzh3JLsCbGjRag0uiDhcYz1JuHq7/view?usp=sharing

于 2021-02-22T11:56:52.540 回答
0

确保你在全局运行 rabbit 服务器,在我的情况下,这就是问题所在。

于 2021-03-03T07:15:25.373 回答
0

此错误意味着 celery 后端设置不正确,因此无法连接到后端。

如果您刚开始使用 django 开始教程 celery。您可以尝试以下设置。

CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//'
CELERY_RESULT_BACKEND = 'db+sqlite:///results.db'
于 2021-07-08T06:01:18.967 回答
0

当你通过 pip 安装 Celery 时,你应该选择你想要使用的版本,例如 redis、rabbitmq、django 等。

如文档中所述:https ://pypi.org/project/celery/

Bundles Celery 还定义了一组捆绑包,可用于安装 Celery 和给定功能的依赖项。

您可以在您的要求中或在 pip 命令行中使用方括号指定这些。可以通过逗号分隔多个包来指定它们。

例子:

$ pip install "celery[librabbitmq]"

$ pip install "celery[librabbitmq,redis,auth,msgpack]"
于 2021-07-27T12:26:40.503 回答