Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pika worker throws exception when running channel.declare_queue

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.

like image 738
Daniel Murphy Avatar asked Sep 06 '12 15:09

Daniel Murphy


2 Answers

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'))
like image 188
Joseph Avatar answered Nov 09 '22 15:11

Joseph


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

like image 34
Franciscon Santos Avatar answered Nov 09 '22 17:11

Franciscon Santos