rabbitMQ中包含100个以上的作业时,AMQP使用者脚本将断开连接,并产生以下错误。重新启动使用者后,它再次执行一定数量的作业,并再次断开连接。 脚本中没有php错误
Error: Broken pipe or closed connection
$conn = new AMQPStreamConnection($this->host,$this->port, $this->user, $this->pass, $this->vhost);
$ch = $conn->channel();
//Declare queue in rabbitmq
$ch->queue_declare($queue, false, true, false, false, false,['x-max-priority' => ['I',maxPriority]]);
//Declare exchange
$ch->exchange_declare($exchange, 'direct', false, true, false);
//Bind exchange with queue
$ch->queue_bind($queue, $this->exchange,$binding_key);
//Create message
//$msg_body = $serviceName.'_'.$serviceValue;
$msg_body = $serviceName;
$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain','priority'=>$priority, 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT));
$ch->basic_publish($msg, $this->exchange,$binding_key);
$ch->close();
$conn->close();
$consumer_tag = 'consumer2';
define('AMQP_DEBUG', true);
$conn = new AMQPStreamConnection($host,$port, $user, $pass, $vhost);
$ch = $conn->channel();
$ch->queue_declare($queue, false, true, false, false, false,['x-max-priority' => ['I', $maxPriority]]);
$ch->exchange_declare($exchange, 'direct', false, true, false);
$ch->queue_bind($queue,$exchange,$binding_key);
$ch->basic_consume($queue, $consumer_tag, false, false, false, false,function ($msg) {
echo "\n########################################PROCESS START################################\n";
if (!empty($msg->body)){
processeEmail($msg->body);
}else{
echo 'Else';
echo '<pre>';
var_dump($msg->body);
}
echo "\n#########################################PROCESS END##################################\n";
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
// Send a message with the string "quit" to cancel the consumer.
if ($msg->body === 'quit') {
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
}
});
register_shutdown_function(function ($ch,$conn) {
$ch->close();
$conn->close();
}, $ch, $conn);
// Loop as long as the channel has callbacks registered
while (count($ch->callbacks)) {
$ch->wait();
}
RabbitMQ 3.6.12
Erlang R16B03-1
PHP 5.6.36
CentOS Linux版本7.5.1804