django celery rabbitmq issue: “WARNING/MainProcess] Received and deleted unknown message. Wrong destination”
My settings.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 code
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 code [ 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](url) On shell I am importing and running as "sample_code.delay()"
Full error stack:
[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={}}
is this issue going to be addressed? I have same issue but its not consistent for every message.
what is you versions and settings?
Here is my settings and custom consumer class. I am using celery as consumer only. These messages are sent to rabbitmq broker by different app. It consume every other message and rest fails with Wrong destination error. For some reason custom consumer do not get these messages. I do not want celerys own task queue consumer to process these messages.
I am using celery 3.1.23, amqp 1.4.9, kombu 3.0.35 and django 1.6.5
celeryconfig.py
CELERY_DEFAULT_QUEUE = settings.JIRA_CELERY_QUEUE
CELERY_DEFAULT_EXCHANGE = settings.JIRA_CELERY_EXCHANGE
CELERY_DEFAULT_EXCHANGE_TYPE = settings.JIRA_CELERY_EXCHANGE_TYPE
CELERY_DEFAULT_ROUTING_KEY = settings.JIRA_CELERY_ROUTING_KEY
CELERY_ACCEPT_CONTENT = ['text/plain', 'json', 'application/json', 'yaml']
CELERY_IGNORE_RESULT = True
CELERY_RESULT_BACKEND = None
CELERY_CREATE_MISSING_QUEUES = False
CELERYD_DISABLE_AUTO_DECLARE = True
consumer.py
from __future__ import absolute_import
from celery import bootsteps
from django.conf import settings
from kombu import Consumer
from kombu import Queue, Exchange
from tools.logger import Logger
logger = Logger.get('jira.consumer', filename=settings.JIRA_CELERYD_LOG_FILE)
class JiraConsumer(bootsteps.ConsumerStep):
def get_consumers(self, channel):
return [Consumer(channel=channel,
queues=[Queue(name=settings.JIRA_CELERY_QUEUE,
exchange=Exchange(settings.JIRA_CELERY_EXCHANGE,
type=settings.JIRA_CELERY_EXCHANGE_TYPE),
routing_key=settings.JIRA_CELERY_ROUTING_KEY)],
on_message=self.on_message,
auto_declare=False),]
def on_message(self, message):
try:
logger.debug('received headers: %r' % (message.headers,))
logger.debug('received message: %r' % (message.payload,))
finally:
message.ack()
celery.py
from __future__ import absolute_import
import os
from celery import Celery
from jira.consumer import JiraConsumer
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')
app = Celery('jira.celery')
app.config_from_object('jira.celeryconfig')
# add the custom consumer bootstep
app.steps['consumer'].add(JiraConsumer)
celery command
celery worker -A jira.celery --without-heartbeat --without-gossip --without-mingle -l debug
Did you figure this out?
@pawaramol22 How did you fix this ? I am also facing the same issue.
I was able to solve this issue.
My Celery setup : I have few celery tasks that uses queue "A" and a custom consumer steps that uses queue "B" to consume tasks.
When I was starting celery with specifying both queues A and B. I was getting error for alternate messages.
celery -A app -Q A,B -c 2
When I start celery without second queue it was working fine.
celery -A app -Q A -c 2
I was using custom consumer and I ran into bug celery version we were using where it was ignoring --without-heartbeat --without-gossip --without-mingle. We had to customize celery project to use these args. Latest version celery (think its 4) should have this fix.
Hello from 2021! I also ran into this issue when trying to integrate Celery with custom consumers into an existing Flask app (I know this is a django repo, but the bug was identical to my situation).
For anyone else who comes across this thread, my problem was exactly the same as @pawaramol22's above: after setting up my Celery app and my custom consumer following the docs, I noticed that every other message would raise the Wrong destination error. I tried applying the --without-heartbeat --without-gossip --without-mingle flags to my startup command, but that did not work for me.
What ended up working was something similar to @viveksyngh's comment from above. I wasn't specifying any queue options via -Q in my celery -A .. worker command, but I was using the task_queues option within my Python config:
celery.py
app = Celery()
app.config_from_object(config)
config.py:
..
task_queues = [ .. ]
..
By removing the task_queues option everything started working fine again. I wrote a test script that sent 10k messages to my custom consumer and all of them were consumed without issues.
Hope this helps anyone looking for a solution in the future!
Hello from 2021! I also ran into this issue when trying to integrate Celery with custom consumers into an existing Flask app (I know this is a django repo, but the bug was identical to my situation).
For anyone else who comes across this thread, my problem was exactly the same as @pawaramol22's above: after setting up my Celery app and my custom consumer following the docs, I noticed that every other message would raise the
Wrong destinationerror. I tried applying the--without-heartbeat --without-gossip --without-mingleflags to my startup command, but that did not work for me.What ended up working was something similar to @viveksyngh's comment from above. I wasn't specifying any queue options via
-Qin mycelery -A .. workercommand, but I was using thetask_queuesoption within my Python config:
celery.pyapp = Celery() app.config_from_object(config)
config.py:.. task_queues = [ .. ] ..By removing the
task_queuesoption everything started working fine again. I wrote a test script that sent 10k messages to my custom consumer and all of them were consumed without issues.Hope this helps anyone looking for a solution in the future!
would you mind sending a PR to improve doc?
I'd love to, but I'm not sure where exactly to send the PR ... should it be in Celery? Or django-celery? Furthermore, I'm not certain what to change in the docs since my "fix" was based on observation -- I have no idea why the bug is happening in the first place and why my fix worked. Making a PR to update docs could potentially mislead future users because we don't know if this is a real bug in Celery, or just undocumented behavior.