老是整忘記,記錄一下rabbitmq使用過程
1、No module named 'celery.backends.amqp' or KeyError: 'backend' #6384
import subprocess from time import sleep import config from celery import Celery url = "amqp://%s:%s@%s:5672/%s" % (config.rabbitmq_user, config.rabbitmq_password, config.rabbitmq_host, config.rabbitmq_vhost) print(url) app = Celery('mq', backend=url, broker=url) @app.task def add(x, y): sleep(10) return x + y
3、消費者
代碼
add.delay(data=data)
celery -A mq worker --loglevel=info # 在消費代碼文件夾下執行上面命令,mq是關鍵代碼的名字