Celery: Error in connecting to RabbitMQ Server

25,499

Solution 1

I was able to resolve this (for those who have and will have the same issue) by doing the following.

I recreated the user I mentioned on my question, but this time with a password. Like this:

sudo rabbitmqctl add_user jm-user1 sample

Then I set the permissions again with this:

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

Restarted rabbitmq server to make sure the changes take effect and made modifications to tasks.py:

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

When I ran,

celery -A tasks worker --loglevel=info

it worked :).

Hopefully, this will be of help to others. Thanks guys!

Solution 2

The broker_url has the format:

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

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

Share:
25,499
jaysonpryde
Author by

jaysonpryde

Updated on July 09, 2022

Comments

  • jaysonpryde
    jaysonpryde almost 2 years

    I am starting to use celery by following this "First Steps with Celery". I exactly used the tasks.py indicated on that link. However when I ran the task using,

    celery -A tasks worker --loglevel=info
    

    I am getting this error:

    [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...
    

    The rabbitmq server is for sure running and below is the snippet of the log regarding the error:

    =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
    

    With this, I did the following to ensure that the 'guest' user has permissions to / vhost:

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

    And then I reloaded/restarted rabbitmq service to make sure the changes will take effect, then ran the task again. However, the error is still the same.

    I even tried creating a different vhost (jm-vhost) and user (jm-user1) and set the permission again to allow all:

    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 ".*" ".*" ".*"
    

    And then modified tasks.py to this:

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

    But when I started the tasks, still, I get the same error. How should I resolve this? Thanks in advance!