django - 如何在 Django 和 Celery 中配置多个代理?

标签 django celery amazon-sqs django-celery django-settings

要求:Django 使用 RabbitMQ(Internal) 和 SQS/Kafka
这两个任务共享通用的 DB/Django 模型。

截至 2016 年 10 月,Django 设置仅支持一种代理配置

如何使用不同的队列配置和代理设置共享任务?

最佳答案

from __future__ import absolute_import
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

app = Celery('proj', broker=["redis://redis:6379/0", "redis://192.168.99.100:6379/0", "redis://192.168.99.102:6379/0"])

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()

关于django - 如何在 Django 和 Celery 中配置多个代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40211852/

相关文章:

python - 覆盖用户对象上的默认 get_absolute_url?

django - 无法在 Django 中捕获 Celery 操作错误

python - 在 cherrypy 中启动 celery 任务

python - 语法错误: invalid syntax - yield from iterable when using celery

amazon-web-services - boto.sqs 连接到非 aws 端点

celery :我是否误解了它的工作原理?

amazon-web-services - 如何设置消息定时器通过SNS主题并路由到订阅的SQS队列?

django - 在 Django 中正确使用 PasswordResetForm

django - webpack 不反射(reflect) js 文件中的更改与 React 和 django

python - 带有 LIMIT 的自定义 get_queryset for django 管理面板