与django和芹菜+ rabbitmq的消费者连接错误?

时间:2012-05-16 01:48:39

标签: python django rabbitmq celery django-celery

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

  • 从pip安装芹菜
  • 通过其存储库提供的debs安装rabbitmq
  • 通过rabbitmqctl为rabbitmq添加了一个用户和vhost,以及该用户的权限
  • 启动了rabbitmq-server
  • 通过pip安装django-celery
  • 设置django-celery,包括其表格
  • 在settings.py中配置了各种内容(BROKER_HOST,BROKER_PORT,BROKER_USER,BROKER_PASSWORD,BROKER_VHOST,以及导入djecelery,调用设置功能并将其添加到安装的应用程序中)。我已经仔细检查了所有这些值是正确的(至少,用户,密码和虚拟主机是正确的。)

现在,当我运行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

5 个答案:

答案 0 :(得分:12)

您的问题出在BROKER_URL

使用额外的VHOST,正确的配置将是:

BROKER_URL='amqp://celeryuser@localhost:5672//'
BROKER_VHOST='/celeryhost'

答案 1 :(得分:4)

对我来说,以下网址结尾有效: ... @本地:5672 / celeryvhost

答案 2 :(得分:4)

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

尝试使用 guest 用户在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 ".*" ".*" ".*"

答案 3 :(得分: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",
)

答案 4 :(得分:1)

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

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

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

然后问题是您为RabbitMQs用户,密码或虚拟主机设置。