1. 正确安装rabbitmq-server
https://blog.csdn.net/qq_33733970/article/details/82881858
[RabbitMQ]Error: unable to connect to node rabbit …
重装rabbitmq-server,重启服务就好了
[root@localhost ~]# rabbitmqctl add_user myuser mypassword
Creating user "myuser"
[root@localhost ~]# rabbitmqctl add_vhost myvhost
Creating vhost "myvhost"
[root@localhost ~]# rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*"
Setting permissions for user "myuser" in vhost "myvhost"
2. tasks.py
from celery import Celery
app = Celery('tasks',broker='amqp://myuser:mypassword@localhost/myvhost',backend='amqp')
@app.task
def add(x,y):
return x+y
3. 启动程序,出现下列信息说明成功:
celery -A tasks worker -l info
-------------- celery@localhost.localdomain v3.1.18 (Cipater)
---- **** -----
--- * *** * -- Linux-3.10.0-862.el7.x86_64-x86_64-with-centos-7.5.1804-Core
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: tasks:0x7f9f818a9a90
- ** ---------- .> transport: amqp://myuser:**@localhost:5672/myvhost
- ** ---------- .> results: amqp
- *** --- * --- .> concurrency: 2 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> celery exchange=celery(direct) key=celery
[tasks]
. tasks.add
[2018-09-28 14:08:51,704: INFO/MainProcess] Connected to amqp://myuser:**@127.0.0.1:5672/myvhost
[2018-09-28 14:08:51,724: INFO/MainProcess] mingle: searching for neighbors
[2018-09-28 14:08:52,785: INFO/MainProcess] mingle: all alone
[2018-09-28 14:08:52,870: WARNING/MainProcess] celery@localhost.localdomain ready.