PHP Rabbitmq 报错Broken pipe

fwrite(): send of 13 bytes failed with errno=32 Broken pipe服务器

fwrite(): send of 21 bytes failed with errno=104 Connection reset by peerfetch

 

用 rabbitmq 作消息队列时报上面的错误,当消费队列一启动,Unacked 瞬间达到好几百。经查:RabbitMQ服务器在短期内发送大量的消息给Consumer,若是你没有来得及Ack的话,那么服务端会积压大量的UnAcked消息,而Consumer若是来不急处理也会处于假死或程序崩溃。spa

后果就是Consmer崩溃后,UnAcked消息又ReQueue不断消耗MQ的资源code

 

解决方案:blog

$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);

$channel = $connection->channel();

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

$channel->basic_qos(null, 10, null); //加上这个就行了 这个10 就是Unacked 里面的值,表示预先取出多少值来消费  prefetch_count