【发布时间】:2021-12-08 04:50:57
【问题描述】:
我正在尝试将我的 Django 应用设置为具有推送通知功能。对于调度通知,我尝试使用 Celery,对于消息代理,我选择了 RabbitMQ。我的应用程序在 Docker 容器中运行,我正在努力让 RabbitMQ 工作。运行docker-compose up 时收到错误消息Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.。这是我的docker-compose.yml 提供的celery 和rabbitmq3 服务:
celery:
restart: always
build:
context: .
command: celery -A test_celery worker -l info
volumes:
- .:/test_celery
env_file:
- ./.env
depends_on:
- app
- rabbitmq3
rabbitmq3:
container_name: "rabbitmq"
image: rabbitmq:3-management-alpine
ports:
- 5672:5672
- 15672:15672
在我的 test_celery -app 中,我有一个名为 celery.py 的文件,其中包含以下内容:
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_celery.settings')
app = Celery('test_celery')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
最后,在我的settings.py 我有这个:CELERY_BROKER_URL = 'amqp://localhost'。
我应该以某种不同的方式定义 CELERY_BROKER_URL 吗?我的 docker-compose 文件有问题吗?希望有任何帮助,我的设置有什么问题?
【问题讨论】:
标签: django docker docker-compose rabbitmq celery