Pika worker throws an exception when running channel.declare_queue

I am writing a python client to receive work messages from the RabbitMQ broker and process tasks, returning the results to another server. My script, which sends messages to the RabbitMQ browser, runs fine, but my worker throws the following error when running channel.declare_queue (queue = 'task_queue')

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

Customer:

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 understanding is greatly appreciated.

EDIT: I found why I got an error with the code above. I indicated delivery_mode = 2 when posting my messages, but when I announced the queue, I forgot to add the Durable = True parameter.

+4
source share
3 answers

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

 connection = pika.BlockingConnection(pika.ConnectionParameters(host=cmdargs.server)) connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) 
+2
source

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

+1
source

I encounter the same problem when I try to make msg message persistent with durable = True.

Try renaming the queue name, it works well with my script. Perhaps start the new_task queue , and run your script again.

0
source

Source: https://habr.com/ru/post/1432753/


All Articles