【问题标题】:django celery rabbitmq issue: "WARNING/MainProcess] Received and deleted unknown message. Wrong destination"django celery rabbitmq 问题:“WARNING/MainProcess] 收到并删除了未知消息。错误的目的地”
【发布时间】:2016-02-11 19:04:14
【问题描述】:

我的设置.py

CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml', 'pickle', 'application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = 'djcelery.backends.cache:CacheBackend'

celery.py 代码

from __future__ import absolute_import
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webapp.settings')
from django.conf import settings  
app = Celery('webapp')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

tasks.py 代码

from __future__ import absolute_import
from celery.utils.log import get_task_logger
from celery import shared_task
import datetime

logger = get_task_logger(__name__)

@shared_task
def sample_code():
    logger.info("Run time:" + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")))
    return None

在 shell 上我以“sample_code.delay()”的形式导入和运行

完整的错误堆栈:

[2016-02-12 00:28:56,331: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?

The full contents of the message body was: body: '\x80\x02}q\x01(U\x07expiresq\x02NU\x03utcq\x03\x88U\x04argsq\x04]q\x05U\x05chordq\x06NU\tcallbacksq\x07NU\x08errbacksq\x08NU\x07tasksetq\tNU\x02idq\nU$f02e662e-4eda-4180-9af4-2c8a1ceb57c4q\x0bU\x07retriesq\x0cK\x00U\x04taskq\rU$app.tasks.sample_codeq\x0eU\ttimelimitq\x0fNN\x86U\x03etaq\x10NU\x06kwargsq\x11}q\x12u.' (232b)
{content_type:u'application/x-python-serialize' content_encoding:u'binary'
  delivery_info:{'consumer_tag': u'None4', 'redelivered': False, 'routing_key': u'celery', 'delivery_tag': 8, 'exchange': u'celery'} headers={}}

请告诉我哪里错了

【问题讨论】:

    标签: django celery django-celery


    【解决方案1】:

    对我来说解决的方法是改变运行 celery 的命令

    问题是:

    celery -A <app_path> worker --loglevel=DEBUG
    

    但是如果我们使用它运行没有问题:

    celery -A <app_path> worker -l info
    

    如果其他人遇到同样的问题,这可能会有所帮助。

    【讨论】:

    • 将日志级别更改为调试只会抑制日志语句,它会实际处理消息吗?
    猜你喜欢
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多