Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery: Error in connecting to RabbitMQ Server

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!

like image 509
jaysonpryde Avatar asked Sep 16 '14 13:09

jaysonpryde


People also ask

How do I connect to RabbitMQ server?

In order for a client to interact with RabbitMQ it must first open a connection. This process involves a number of steps: Application configures the client library it uses to use a certain connection endpoint (e.g. hostname and port) The library resolves the hostname to one or more IP addresses.

What is the difference between RabbitMQ and celery?

Celery is an asynchronous distributed task queue. RabbitMQ is a message broker which implements the Advanced Message Queuing Protocol (AMQP).


2 Answers

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!

like image 139
jaysonpryde Avatar answered Nov 20 '22 19:11

jaysonpryde


The broker_url has the format:

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

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

like image 26
ForRealHomie Avatar answered Nov 20 '22 20:11

ForRealHomie