【发布时间】:2013-04-05 19:57:44
【问题描述】:
我正在处理一个巨大的 xml 文档(其中包含大约一百万个条目),然后使用 rabbitmq 将格式化版本导入到数据库中。每次发布大约 200,000 个条目后,我都会收到一个损坏的管道错误,并且 rabbitmq 无法从中恢复。
注意错误:fwrite(): send of 2651 bytes failed with errno=11 资源暂时不可用 [/var/www/ribbon/app/Console/Command/lib/php_amqplib/amqp.inc,行 439]
注意错误:fwrite(): send of 33 bytes failed with errno=104 对等方重置连接 [/var/www/ribbon/app/Console/Command/lib/php_amqplib/amqp.inc,行 439]
注意错误:fwrite(): send of 19 bytes failed with errno=32 Broken [/var/www/ribbon/app/Console/Command/lib/php_amqplib/amqp.inc 中的管道, 第439行]
这随后会导致节点关闭错误,需要手动终止进程才能从中恢复。
这些是我的类方法:-
public function publishMessage($message) {
if (!isset($this->conn)) {
$this->_createNewConnectionAndChannel();
}
try {
$this->ch->basic_publish(
new AMQPMessage($message, array('content_type' => 'text/plain')),
$this->defaults['exchange']['name'],
$this->defaults['binding']['routing_key']
);
} catch (Exception $e) {
echo "Caught exception : " . $e->getMessage();
echo "Creating new connection.";
$this->_createNewConnectionAndChannel();
$this->publishMessage($message); // try again
}
}
protected function _createNewConnectionAndChannel() {
if (isset($this->conn)) {
$this->conn->close();
}
if(isset($this->ch)) {
$this->ch->close();
}
$this->conn = new AMQPConnection(
$this->defaults['connection']['host'],
$this->defaults['connection']['port'],
$this->defaults['connection']['user'],
$this->defaults['connection']['pass']
);
$this->ch = $this->conn->channel();
$this->ch->access_request($this->defaults['channel']['vhost'], false, false, true, true);
$this->ch->basic_qos(0 , 20 , 0); // fair dispatching
$this->ch->queue_declare(
$this->defaults['queue']['name'],
$this->defaults['queue']['passive'],
$this->defaults['queue']['durable'],
$this->defaults['queue']['exclusive'],
$this->defaults['queue']['auto_delete']
);
$this->ch->exchange_declare(
$this->defaults['exchange']['name'],
$this->defaults['exchange']['type'],
$this->defaults['exchange']['passive'],
$this->defaults['exchange']['durable'],
$this->defaults['exchange']['auto_delete']
);
$this->ch->queue_bind(
$this->defaults['queue']['name'],
$this->defaults['exchange']['name'],
$this->defaults['binding']['routing_key']
);
}
任何帮助将不胜感激。
【问题讨论】:
-
你试过PECL AMQP extension吗?根据经验,它的片状要少得多,better maintained.