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()