Celery:连接到RabbitMQ服务器时出错



我按照"芹菜的第一步"开始使用芹菜。我完全使用了链接上显示的tasks.py。然而,当我使用运行任务时

celery -A tasks worker --loglevel=info

我得到这个错误:

[2014-09-16 20:52:57,427: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed. Trying again in 2.00 seconds...

rabbitmq服务器肯定在运行,下面是关于错误的日志片段:

=ERROR REPORT==== 16-Sep-2014::20:53:09 ===
exception on TCP connection <0.235.0> from 127.0.0.1:58162
{channel0_error,starting,
            {amqp_error,access_refused,
                        "AMQPLAIN login refused: user 'guest' - invalid credentials",
                        'connection.start_ok'}}
=INFO REPORT==== 16-Sep-2014::20:53:09 ===
closing TCP connection <0.235.0> from 127.0.0.1:58162
=INFO REPORT==== 16-Sep-2014::20:53:15 ===
accepted TCP connection on [::]:5672 from 127.0.0.1:58163
=INFO REPORT==== 16-Sep-2014::20:53:15 ===
starting TCP connection <0.239.0> from 127.0.0.1:58163
=ERROR REPORT==== 16-Sep-2014::20:53:18 ===
exception on TCP connection <0.239.0> from 127.0.0.1:58163
{channel0_error,starting,
            {amqp_error,access_refused,
                        "AMQPLAIN login refused: user 'guest' - invalid credentials",
                        'connection.start_ok'}}
=INFO REPORT==== 16-Sep-2014::20:53:18 ===
closing TCP connection <0.239.0> from 127.0.0.1:58163

有了这个,我做了以下事情来确保"访客"用户有权访问/vhost:

sudo rabbitmqctl set_permissions -p / guest ".*" ".*" ".*"

然后我重新加载/重新启动了rabbitmq服务,以确保更改生效,然后再次运行该任务。然而,错误仍然是一样的。

我甚至尝试创建一个不同的vhost(jm-vhost)和user(jm-user1),并再次设置权限以允许所有:

sudo rabbitmqctl add_vhost jm-vhost
sudo rabbitmqctl add_user jm-user1 ""   --> "" to make it passwordless (is this correct?)
sudo rabbitmqctl set_permissions -p /jm-vhost jm-user1 ".*" ".*" ".*"

然后将tasks.py修改为:

app = Celery('tasks', broker='amqp://jm-user1@localhost//jm-vhost')

但当我开始执行任务时,仍然会出现同样的错误。我应该如何解决此问题?提前感谢!

我通过以下操作解决了这个问题(对于那些已经和将要遇到相同问题的人)。

我重新创建了我在问题中提到的用户,但这次使用了密码。像这样:

sudo rabbitmqctl add_user jm-user1 sample

然后我用这个再次设置权限:

sudo rabbitmqctl set_permissions -p jm-vhost jm-user1 ".*" ".*" ".*"

重新启动rabbitmq-服务器以确保更改生效,并对任务进行了修改。py:

app = Celery('tasks', broker='amqp://jm-user1:sample@localhost/jm-vhost')

当我跑步时,

celery -A tasks worker --loglevel=info

它奏效了:)。

希望这能对其他人有所帮助。谢谢大家!

broker_url的格式为:

transport://userid:password@hostname:port/virtual_host

http://docs.celeryproject.org/en/latest/userguide/configuration.html#broker-url

相关内容

  • 没有找到相关文章

最新更新