写好celery任务文件,使用celery -A app worker --loglevel=info启动时,报告如下错误:
[2019-01-29 01:19:26,680: ERROR/MainProcess] consumer: Cannot connect to amqp://sunlight:**@127.0.0.1:5672/celery: [Errno 104] Connection reset by peer.
Trying again in 4.00 seconds...
检查了很久,终于发现是celery配置的broker的url写错了,
rabbitmqctl add_user sunlight sunlight123
rabbitmqctl add_vhost /celery
rabbitmqctl set_permissions -p /celery sunlight ".*" ".*" ".*"
app = Celery(__name__, broker="amqp://sunlight:sunlight123@localhost:5672/celery", backend="redis://localhost")
上门的标红处,显然是错误的,应该替换为如下:
app = Celery(__name__, broker="amqp://sunlight:sunlight123@localhost:5672//celery", backend="redis://localhost")
即可解决问题。