Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery didn't operate well because of errno 104

I have a problem executing celery on rabbitmq-server. I searched and found a link, but it doesn't help me. My env is ubuntu 14.04, python 2.7.6, celery 3.1.15, Django 1.7. Referencing a link, I installed rabbitmq-server locally. I added user, vhost in rabbitmq-server and set permissions.

$ sudo rabbitmqctl add_user tonyg password
$ sudo rabbitmqctl add_vhost vir_host
$ sudo rabbitmqctl set_permissions -p vir_host tonyg ".*" ".*" ".*"

My celery's setting in django follows.

BROKER_URL = 'amqp://tonyg:password@localhost:5672//vir_host'
CELERY_RESULT_BACKEND = 'amqp://tonyg:password@localhost:5672//vir_host'
CELERY_ACCEPT_CONTENT = [u'application/x-python-serialize', u'image/jpeg', u'image/bmp', u'image/png', u'image/tiff']
CELERY_TIMEZONE = 'Asia/Tokyo'
CELERY_ENABLE_UTC = True
CELERY_IGNORE_RESULT = False

I don't set anything about rabbitmq-server other than default configs.

I executed celery like this.

$ celery -A MyProj worker -l info

-------------- celery@ip-172-31-3-10 v3.1.15 (Cipater)
---- **** ----- 
--- * ***  * -- Linux-3.13.0-36-generic-x86_64-with-Ubuntu-14.04-trusty
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         MyProj:0x7f7453328b10
- ** ---------- .> transport:   amqp://tonyg:**@localhost:5672//vir_host
- ** ---------- .> results:     amqp://tonyg:password@localhost:5672//vir_host
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- 
--- ***** ----- [queues]
 -------------- .> celery           exchange=celery(direct) key=celery


[tasks]
  . MyProj.tasks. ......
  . MyProj.tasks. ......

[2014-10-29 15:07:50,241: ERROR/MainProcess] consumer: Cannot connect to amqp://tonyg:**@127.0.0.1:5672//vir_host: [Errno 104] Connection reset by peer.
Trying again in 2.00 seconds...

[2014-10-29 15:07:55,251: ERROR/MainProcess] consumer: Cannot connect to amqp://tonyg:**@127.0.0.1:5672//vir_host: [Errno 104] Connection reset by peer.
Trying again in 4.00 seconds...

When i set celery using default guest identifier,

BROKER_URL = 'amqp://guest:guest@localhost:5672//'
CELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//'

it does operate well. I don't know why. Could anyone help me? Thank you.

like image 848
BlueFrog Avatar asked Oct 29 '14 06:10

BlueFrog


2 Answers

Run rabbitmqctl list_vhosts. The output will be:

Listing vhosts ...
/
vir_host
...done.

Thus the URL has to be:

amqp://tonyg:**@localhost:5672/vir_host
like image 182
Krzysztof Szularz Avatar answered Nov 07 '22 00:11

Krzysztof Szularz


Thanks to @Krzysztof Szularz answer. Turns out your url is incorrect. It has to be

BROKER_URL = 'amqp://tonyg:password@localhost:5672/vir_host'

Now you are connecting via localhost and it works fine. If you want to connect remotely, it wont work. Your account is just a guest account and it doesn't have admin privileges. So that user has to connect via locahost ONLY. If you want that user to access from a virutal host, you need to give him privileges to do so.

Run this command to give user admin privileges.

rabbitmqctl set_user_tags tonyg administrator

You can read more about this here.

like image 37
Pandikunta Anand Reddy Avatar answered Nov 06 '22 23:11

Pandikunta Anand Reddy