python - Celery 连接到远程服务器broker_url

标签 python django celery django-celery djcelery

我正在按照docs守护 celery 。

我的 BROKER_URL 已按以下格式设置:- 'amqp://<user>:<password>@<ip>/<vhost>' .

所以,当我手动启动 celery 时,celery worker -A app_name ,它与远程服务器连接。但是当我守护它时,它会与本地主机 amqp 连接。有什么原因吗?

这是我创建 celery 对象的方法:-

app = Celery('c26_search')    
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.conf.update(
    CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
)
print app.conf.BROKER_URL  # prints remote url

我的settings.py文件:-

CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
BROKER_URL = `'amqp://<user>:<password>@<ip>/<vhost>'`

为什么表现得这么奇怪?即使它打印了远程 IP url,但仍然尝试连接本地 amqp?

最佳答案

嗯,我找到了问题的答案:-

通行证经纪人网址为 CELERY_OPTSCELERYD_OPTS="-n worker2.%h --broker=amqp://<user>:<password>@<ip>/<vhost>"在 celeryd 文件中。

关于python - Celery 连接到远程服务器broker_url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39184400/

相关文章:

python - Pywin32 将 .docx 保存为 pdf

python - 创建一个requirements.txt文件

python - 查询django模板中的多对多字段

django - 覆盖 AbstractUser 模型的默认 django 用户名验证器

Python:模拟在 celery 任务中不起作用

python - 基于每日时间序列数据框创建工作日/周末时间序列数据框

python - Celery 由于预取而执行多任务

django - 如何使用 Django 查询将两个 ManyToMany 字段相交?

Django&Celery-路由问题

django - ConnectionAbortedError - 如果 Celery 停止/失败或 Redis 未启动。我如何捕获/除此错误/