使用rabbitmq作为芹菜的经纪人。运行命令时出现问题
celery -A proj worker --loglevel=info
芹菜控制台显示此
[2017-06-23 07:57:09,261: ERROR/MainProcess] consumer: Cannot connect to amqp://bruce:**@127.0.0.1:5672//: timed out.
Trying again in 2.00 seconds...
[2017-06-23 07:57:15,285: ERROR/MainProcess] consumer: Cannot connect to amqp://bruce:**@127.0.0.1:5672//: timed out.
Trying again in 4.00 seconds...
以下是来自rabbitmq的日志
=ERROR REPORT==== 23-Jun-2017::13:28:58 ===
closing AMQP connection <0.18756.0> (127.0.0.1:58424 -> 127.0.0.1:5672):
{handshake_timeout,frame_header}
=INFO REPORT==== 23-Jun-2017::13:29:04 ===
accepting AMQP connection <0.18897.0> (127.0.0.1:58425 -> 127.0.0.1:5672)
=ERROR REPORT==== 23-Jun-2017::13:29:14 ===
closing AMQP connection <0.18897.0> (127.0.0.1:58425 -> 127.0.0.1:5672):
{handshake_timeout,frame_header}
=INFO REPORT==== 23-Jun-2017::13:29:22 ===
accepting AMQP connection <0.19054.0> (127.0.0.1:58426 -> 127.0.0.1:5672)
任何意见都会受到赞赏。
答案 0 :(得分:1)
我知道它已晚了
但是今天我遇到了同样的问题,花了差不多一个小时才找到确切的解决办法。认为它可能会帮助别人
我使用的是芹菜版4.1.0
希望您已正确配置RabbitMQ,如果没有,请按照页面http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html#setting-up-rabbitmq
中的说明对其进行配置还要交叉检查经纪人网址是否正确。这是brocker url语法 AMQP:// <强> USER_NAME 强>:密码强> @的本地主机强> / <强>主机名强>
您可能不需要指定端口号,因为它会自动选择默认值
如果您按照上面的安装教程链接中的相同变量进行操作,那么您的Brocker网址就会如此 的 AMQP://为myuser:输入mypassword @本地/ myvhost 强>
遵循此项目结构
Project
../app
../Project
../settings.py
../celery.py
../tasks.py
../celery_config.py
<强> celery_config.py 强>
# - - - - - - - - - -
# BROKER SETTINGS
# - - - - - - - - - -
# BROKER_URL = os.environ['APP_BROKER_URL']
BROKER_HEARTBEAT = 10
BROKER_HEARTBEAT_CHECKRATE = 2.0
# Setting BROKER_POOL_LIMIT to None disables pooling
# Disabling pooling causes open/close connections for every task.
# However, the rabbitMQ cluster being behind an Elastic Load Balancer,
# the pooling is not working correctly,
# and the connection is lost at some point.
# There seems no other way around it for the time being.
BROKER_POOL_LIMIT = None
BROKER_TRANSPORT_OPTIONS = {'confirm_publish': True}
BROKER_CONNECTION_TIMEOUT = 20
BROKER_CONNECTION_RETRY = True
BROKER_CONNECTION_MAX_RETRIES = 100
<强> celery.py 强>
from __future__ import absolute_import, unicode_literals
from celery import Celery
from Project import celery_config
app = Celery('Project',
broker='amqp://myuser:mypassword@localhost/myvhost',
backend='amqp://',
include=['Project'])
# Optional configuration, see the application user guide.
# app.conf.update(
# result_expires=3600,
# CELERY_BROKER_POOL_LIMIT = None,
# )
app.config_from_object(celery_config)
if __name__ == '__main__':
app.start()
<强> tasks.py 强>
from __future__ import absolute_import, unicode_literals
from .celery import app
@app.task
def add(x, y):
return x + y
然后从项目目录“celery -A Project worker -l info”启动芹菜
一切都会好的。
答案 1 :(得分:0)
在settings.py中设置CELERY_BROKER_POOL_LIMIT =无