amqp 被添加到 celery broker url

问题描述 投票:0回答:0

使用

redis://redis:6379/0
指定 broker_url 被覆盖为
amqp://guest:**@redis%2F%2Fredis%3A6379%2F0:5672/

日志 无法连接到 amqp://guest:**@redis%2F%2Fredis%3A6379%2F0:5672//: [Errno -2] 名称或服务未知。

设置

结构

config/
  settings/
    common.py
    dev.py
  celery.py

docker-compose.yml

services:
  django: &django_container
    build:
      context: .
      dockerfile: docker/django/Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    volumes:
      - .:/facebook_scraper
    environment:
      DOTTED_SETTINGS_PATH: 'config.settings.dev'
    env_file:
      - ./dev.env
    depends_on:
      - postgres
      - redis
      - selenium
  
  redis:
    image: redis:7.0.8
    ports:
      - "6379:6379"
  celery_worker:
    <<: *django_container
    ports: []
    command: celery -A config.celery worker -l INFO

芹菜.py

import os
from celery import Celery

dotted_settings_path = os.environ.get('DOTTED_SETTINGS_PATH')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', dotted_settings_path)

app = Celery(
    'facebook_scraper',
    # backend='redis://redis:6379/0',
    # broker='redis://redis:6379/0',
)
app.conf.update(
    broker_url='redis://redis:6379/0',
)
# app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
django celery
© www.soinside.com 2019 - 2024. All rights reserved.