2

I'm setting up a task in Celery to make it 'consume' from a certain topic exchange. When I send the message to the exchange in question I get the error: "Received and deleted an unknown message. Wrong destination?!?" on the celery console.

I've made a separate project folder to replicate the issue where everything is called test-something with the following structure:

celery-test/  
  L celery.py  
  L celeryconfig.py  
  L tasks.py

I've seen various StackOverflow questions and GitHub issues referring to the librabbitmq package. The solution here would be to uninstall this package but I don't even have it installed, so that led me nowhere. Some of the questions/issues found that suggest this solution:
- https://github.com/celery/celery/issues/3675
- Celery &Rabbitmq:WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?- a experiment on the GIT

I've also tried playing with the task routing settings, as I assume the issue lies there atm, but I can't get it to work.

For anyone wondering why the port is off by 1, that's because it's pointing to the rabbitmq in my docker container which couldn't use 5672 anymore.

celery.py

app = Celery('celery_test', include=['celery_test.tasks'])
app.config_from_object('celery_test.celeryconfig')

celeryconfig.py

broker_url = 'amqp://guest:guest@localhost:5673//'
result_backend = 'rpc://'

default_exchange = Exchange('default', type='direct')
test_exchange = Exchange('test_exchange', type='topic')
task_queues = (
    Queue('default', default_exchange, routing_key='default'),
    Queue('test_queue', test_exchange, routing_key='test123test')
)

task_routes = {
    'celery_test.tasks.test_method': {
        'queue': 'test_queue'
    }
}

tasks.py

@app.task
def test_method():
    print('test_method')
    return 'test_method'

And then the file I used to send a message: send.py

connection = pika.BlockingConnection(pika.URLParameters('amqp://guest:guest@localhost:5673/'))
channel = connection.channel()

exchange = 'test_exchange'
routing_key = 'test123test'
message = 'Testmessage'

channel.exchange_declare(exchange=exchange, exchange_type='topic', durable=True)

channel.basic_publish(exchange=exchange, routing_key=routing_key, body=message)
connection.close()
Wim Naudts
  • 45
  • 9
StoopArno
  • 21
  • 1
  • 3

2 Answers2

0

This may not really be an answer and instead is more of a follow-up. But i thought I'd let people know who come across this problem. (This post is all my interpretation, and since I'm new to celery you should probably take this with a grain of salt.)

So basically the reason I think this happens is because Celery doesn't understand the message. Celery requires a lot of headers and other properties before it can understand what the messesage is trying to do.

It is possible to emulate these headers be reverse engineering them, but I'm not going to go through that, as there are simpler ways to solve the aplication that I'm plannig on making.

If there is someone reading this with more exprience on the subject, feel free to correct me.

StoopArno
  • 21
  • 1
  • 3
0

This is for anyone affected by this in 2021. I have an old service using celery 3.1.x (let's call it "legacy") and a more recently created service using celery 5.0.x version (let's call it "modern").

In the modern codebase, Celery.signature() method is used to create a signature, then apply_async() is called to invoke a task in legacy. The legacy celery did receive my message but discarded it with this error:

Received and deleted unknown message. Wrong destination?!?

I solved the problem by adding this line in celeryconfig.py file:

task_protocol = 1

Explanation is here: https://github.com/celery/celery/issues/3675#issuecomment-294129297

Raiyan
  • 1,589
  • 1
  • 14
  • 28