8

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.

2 Answers 2

15

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
7
  • Url is correct. But the user doesn't have admin privileges to connect via virtual host. Oct 29, 2014 at 7:32
  • @Krzysztof Szularz Thank you so much. I thought i have tried amqp://tonyg:**@localhost:5672/vir_host. But, I tried again. It does work!!! I made a silly mistake. But, i wanna know why setting (amqp://tonyg:**@localhost:5672/vir_host) does operate well in a Mac OS X. Anyway, thank you so much.
    – BlueFrog
    Oct 29, 2014 at 7:33
  • I don't get the question. amqp://tonyg:**@localhost:5672/vir_host operates well because it's a valid URL for vhost you've created. The one with two slashes is not a valid one, unless vhost is called /vir_host which isn't the case. Oct 29, 2014 at 7:36
  • @Krzysztof Szularz I typed wrong url. I can't modify comment after 5 mins. I set BROKER_URL = 'amqp://tonyg:password@localhost:5672//vir_host' on Mac OS X, but it does work correctly. Do u know why?
    – BlueFrog
    Oct 29, 2014 at 7:43
  • @KrzysztofSzularz i sincerely apologize. its my mistake @BlueFrog your virual host name is might be /vir_host but not vir_host Oct 29, 2014 at 7:44
3

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.

1
  • @KrzysztofSzularz forgot that he is connecting via localhost only. Oct 29, 2014 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.