芹菜:无法连接到 RabbitMQ



使用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)

任何意见将不胜感激。

我知道它晚了

但是我今天遇到了同样的问题,花了将近一个小时来找到确切的解决方法。以为它可能会帮助别人

我正在使用芹菜版本 4.1.0

希望您已经正确配置了 RabbitMQ,如果没有,请按照页面中提到的配置它 http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html#setting-up-rabbitmq

还要交叉检查代理 URL 是否正确。这是布罗克网址语法 amqp://user_namepassword@localhost/host_name

您可能不需要指定端口号,因为它将自动选择默认端口号

如果您遵循上方设置教程链接中的相同变量,您的 Brocker 网址将如下所示amqp://myuser:mypassword@localhost/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

然后从项目目录中使用"芹菜 -A 项目工作人员 -l 信息">启动芹菜

一切都会好起来的。

set CELERY_BROKER_POOL_LIMIT = None in settings.py

此解决方案适用于 GCP 用户。

我一直在研究 GCP 并面临同样的问题。

错误消息是:

[2022-03-15 16:56:00,318:错误/主进程] 消费者:无法连接 amqp://root:**@34.125.161.132:5672/vhost:超时。

我花了将近一个小时来解决这个问题,终于找到了解决方案

我们必须在Firewall规则中添加端口号5672

步骤:

  1. 转到防火墙
  2. 选择默认允许 HTTP 规则
  3. 按编辑
  4. 搜索"指定的协议和端口">
  5. 在TCP框中添加5672
  6. (如果要添加更多端口的示例:80,5672,8000)

保存更改,然后就可以了!

相关内容

  • 没有找到相关文章

最新更新