Question

I'm writing a python client to accept job messages from a RabbitMQ broker and process the jobs, returning the results to another server. My script that sends messages to the RabbitMQ broker starts up fine, but my worker throws the following error when running channel.declare_queue(queue='task_queue')

pika.exceptions.AMQPChannelError: (406, "PRECONDITION_FAILED - parameters for queue 'task_queue' in vhost '/' not equivalent")

Client:

import pika    
connection = pika.BlockingConnection(pika.ConnectionParameters(host=cmdargs.server))
channel = connection.channel()
channel.queue_declare(queue='task_queue')
channel.basic_qos(prefetch_count=1)
channel.basic_consume(ProcJobCallback, queue='task_queue')
channel.start_consuming()

Server method that interacts with RabbitMQ:

def addNewJob(self, newJob):
        self.jobList.append(newJob)
        connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
        channel = connection.channel()
        channel.queue_declare(queue='task_queue')

        for tile in newJob.TileStatus:
                message = "{0},{1},{2}".format(newJob, tile[0], tile[1])
                channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties(delivery_mode = 2, ))
        connection.close()

Any help or insight is greatly appreciated.

EDIT: I discovered why I was getting an error with the code listed above. I was specifying delivery_mode=2 when publishing my messages, but when I declared the queue, I forgot to add the Durable=True parameter.

Was it helpful?

Solution

Are you sure you are connecting to the same server (host) on the publisher and consumer side?

connection = pika.BlockingConnection(pika.ConnectionParameters(host=cmdargs.server))

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

OTHER TIPS

if your queue is durable just remove the declaration "channel.queue_declare(queue='task_queue')", that should be enough in your case.

i meet the same problem when I try to make the queue msg persistent with durable=True.

Try to rename the queue name, it works well with my script. Maybe kill the queue new_task, and re-run your script also works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top