在RabbitMQ PHP中设置消息优先级

use*_*289 3 php message-queue rabbitmq

我已经在RabbitMQ for Java,Spring等中找到了很多设置消息优先级的例子,但到目前为止我还没有找到如何在PHP中实现它.

事实上,该$channel->basic_publish()函数似乎不支持提供其他参数(https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php),即使您可以在RabbitMQ中执行此操作GUI.

有没有人在PHP中使用RabbitMQ的消息优先级?

use*_*289 5

好吧,它一直盯着我.您可以在实际message对象中设置优先级,而不是在将其推入队列时:

$msg = new AMQPMessage("Hello World!", array(
    'delivery_mode' => 2,
    'priority' => 1,
    'timestamp' => time(),
    'expiration' => strval(1000 * (strtotime('+1 day midnight') - time() - 1))
));
Run Code Online (Sandbox Code Playgroud)