Rabbitmq和Celery结合使用

65 篇文章 4 订阅

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值