RabbitMQ Consumer throwing error when using priority

时间:2017-04-10 02:42:33

标签: php rabbitmq

I am trying to switch my task queue to utilize priority support, I was able to set the x-max-priority value creating the task, but when I try to fetch a task, it is throwing an error.

Is there a special way to fetch the task using a consumer?

$channel->queue_declare('task_queue', false, true, false, false);

PhpAmqpLib\Exception\AMQPProtocolChannelException' with message 'PRECONDITION_FAILED - inequivalent arg 'x-max-priority' for queue 'task_queue' in vhost 'vhost': received none but current is the value '100' of type 'signedint'' in /var/www/html/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php:188

1 个答案:

答案 0 :(得分:0)

You need to $channel->queue_declare with identical parameters on both sides.

So you must set the priority property on both sides like

$channel->queue_declare('task_queue', false, true, false, false, false, $parameters);

where $parameters is an array declared like

$parameters = [
    'x-max-priority' => ['I', 100],
];