11

我正在尝试用 django 和 rabbit-mq 设置 celeryd。到目前为止,我已经完成了以下工作:

  • 从 pip 安装的芹菜
  • 通过其存储库中可用的 deb 安装 rabbitmq
  • 通过 rabbitmqctl 向 rabbitmq 添加了用户和虚拟主机,以及该用户的权限
  • 启动rabbitmq-server
  • 通过 pip 安装 django-celery
  • 设置 django-celery,包括它的表
  • 在settings.py中配置好各种东西(BROKER_HOST、BROKER_PORT、BROKER_USER、BROKER_PASSWORD、BROKER_VHOST,以及导入djecelery,调用setup函数并添加到INSTALLED APPS)。我已经仔细检查了所有这些值都是正确的(至少,用户、密码和虚拟主机是正确的)。

所以现在,当我运行时python manage.py celeryd -l info出现连接错误(见下文)。有人知道为什么吗?

$ python manage.py celeryd -l info
/usr/local/lib/python2.7/dist-packages/djcelery/loaders.py:108: 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 "
[2012-05-15 18:38:04,486: WARNING/MainProcess]  

 -------------- celery@ubuntu v2.5.3
---- **** -----
--- * ***  * -- [Configuration]
-- * - **** ---   . broker:      amqp://celeryuser@localhost:5672/celeryhost
- ** ----------   . loader:      djcelery.loaders.DjangoLoader
- ** ----------   . logfile:     [stderr]@INFO
- ** ----------   . concurrency: 1
- ** ----------   . events:      OFF
- *** --- * ---   . beat:        OFF
-- ******* ----
--- ***** ----- [Queues]
 --------------   . celery:      exchange:celery (direct) binding:celery


[Tasks]


[2012-05-15 18:38:04,562: INFO/PoolWorker-1] child process calling self.run()
[2012-05-15 18:38:04,565: WARNING/MainProcess] celery@ubuntu has started.
[2012-05-15 18:38:07,572: ERROR/MainProcess] Consumer: Connection Error: [Errno 104] Connection reset by peer. Trying again in 2 seconds...
^C[2012-05-15 18:38:08,434: WARNING/MainProcess] celeryd: Hitting Ctrl+C again will terminate all running tasks!
[2012-05-15 18:38:08,435: WARNING/MainProcess] celeryd: Warm shutdown (MainProcess)
[2012-05-15 18:38:09,372: INFO/PoolWorker-1] process shutting down
[2012-05-15 18:38:09,373: INFO/PoolWorker-1] process exiting with exitcode 0
[2012-05-15 18:38:09,376: INFO/MainProcess] process shutting down
4

5 回答 5

12

你的问题在BROKER_URL.

加上一个额外VHOST的 ,正确的配置将是:

BROKER_URL='amqp://celeryuser@localhost:5672//'
BROKER_VHOST='/celeryhost'
于 2012-09-27T21:46:13.287 回答
4

对我来说,以下 URL 结尾有效: ...@localhost:5672/celeryvhost

于 2013-06-27T13:11:49.197 回答
4

我对 RabbitMQ 有类似的问题,问题是我的用户无权在 RabbitMQ 中创建消息。

尝试使用访客用户在您的 RabbitMQ 服务器上运行以下脚本,如果它创建作业,请使用您的用户尝试:

from celery import Celery

app = Celery('tasks', broker='amqp://radek:**@localhost:5672//')

@app.task
def add(x, y):
    return x + y

如果您遇到相同的错误,只需为您的用户设置权限:

rabbitmqctl set_permissions -p / radek ".*" ".*" ".*"
于 2014-10-29T11:24:08.347 回答
1

你的 rabbitmq 服务器不能正常启动和/或配置。验证它并再试一次 - 或者,更好的是,如果你只是想测试一些东西并且你与队列无关,取出 rabbitmq 并开始使用 redis。它更容易配置。

我刚刚从我的一个项目中剪切并粘贴了这段代码,它工作得很好:

import djcelery
from datetime import timedelta

djcelery.setup_loader()


BROKER_BACKEND = "redis"
BROKER_HOST = "localhost"
BROKER_PORT = 6379
BROKER_VHOST = "0"

CELERYD_LOG_LEVEL  = 'DEBUG'
CELERY_RESULT_BACKEND = "redis"
CELERY_TASK_RESULT_EXPIRES = 150000
REDIS_HOST = "localhost"
REDIS_PORT = 6379
REDIS_DB = "0"
CELERYD_CONCURRENCY = 1
CELERYD_MAX_TASKS_PER_CHILD = 4

CELERY_IMPORTS = (
    "apps.app1.tasks",
    "apps.app2.tasks",
)
于 2012-05-16T04:30:33.690 回答
1

您的 BROKER_URL 在 settings.py 中是什么样的?

默认情况下,RabbitMQ 有一个访客用户,所以如果你可以连接

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

那么问题是您对 RabbitMQs 用户、密码或虚拟主机的设置。

于 2012-06-10T21:47:39.850 回答