rabbitmq php 限流
<?php require_once './vendor/autoload.php'; use PhpAmqpLib\Connection\AMQPStreamConnection; $connection = new AMQPStreamConnection('127.0.0.1', 5672, 'test', 'test', '/'); $channel = $connection->channel(); $channel->queue_declare('qos_queue', false, false, false, false); //第二个参数代表:每次只消费n条 本例为1条 //向消费者发送n条消息 待消费者ack后 再发下个n条 ... $channel->basic_qos(null, 1, null); function process_message($message) { echo $message->body.PHP_EOL; //消费完消息之后进行应答,告诉rabbit我已经消费了,可以发送下一组了 $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']); } $channel->basic_consume('qos_queue', '', false, false, false, false, 'process_message'); while ($channel->is_consuming()) { // After 10 seconds there will be a timeout exception. $channel->wait(null, false, 30000); }
<?phprequire_once './vendor/autoload.php';use PhpAmqpLib\Connection\AMQPStreamConnection;
$connection = new AMQPStreamConnection('127.0.0.1', 5672, 'mq', 'mq123', '/');$channel = $connection->channel();
$channel->queue_declare('qos_queue', false, false, false, false);
//第二个参数代表:每次只消费n条 本例为1条//向消费者发送n条消息 待消费者ack后 再发下个n条 ...$channel->basic_qos(null, 1, null);
function process_message($message){echo $message->body.PHP_EOL; //消费完消息之后进行应答,告诉rabbit我已经消费了,可以发送下一组了 $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);}
$channel->basic_consume('qos_queue', '', false, false, false, false, 'process_message');
while ($channel->is_consuming()) { // After 10 seconds there will be a timeout exception. $channel->wait(null, false, 30000);}————————————————版权声明:本文为CSDN博主「qq_42724459」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/qq_42724459/article/details/109531350