4

I am trying to consume Celery task from a Rabbitmq queue.

My tasks.py is below

from celery import Celery

app=Celery('tasks',broker ='amqp://localhost//')

app.conf.task_default_queue = 'e'

@app.task(name='hello')
def hello():
  print('hello')

and

import pika

connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='e')

def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)

channel.basic_consume(
    queue='e', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

But I am getting this error amqp.exceptions.PreconditionFailed: Queue.declare: (406) PRECONDITION_FAILED - inequivalent arg. I dont know why?

newUser
  • 386
  • 5
  • 17
  • Your `app` definition is likely missing a `task_queues` argument with the 'e' queue definition. The queue definition (`from Kombu import Queue`) must have matching arguments with your consume task, i.e. `on_message_callback` and `auto_ack`. – Pawel Kranzberg Mar 31 '22 at 08:55

0 Answers0