/** * 检查ack状态,如果返回的是标准错误包,说明命令处理失败了,读取错误信息 * @param binary string $res_body: 响应消息流 * @return false如果ack不是status ok, 否则返回true */ private function _ack_status_ok($res_body) { // load command type $type = BigpipeFrame::get_command_type($res_body); if (MetaAgentFrameType::UNKNOWN_TYPE == $type) { BigpipeLog::warning('[no cmd_type in ack]'); return false; } if ($type == MetaAgentFrameType::ACK_ERROR_PACK) { // 有错误,返回的是错误提示包 $ack = new MetaAgentErrorAckFrame(); if (!$ack->load($res_body)) { $this->last_error_message = $ack->last_error_message(); } else { $this->last_error_message = $ack->error_msg; } BigpipeLog::warning('[%s:%u][%s][ack error][cmd_type:%d][err:%s]', __FILE__, __LINE__, __FUNCTION__, $ack->command_type, $this->last_error_message); return false; // 不是正常ack } // 处理标准错误包 return true; }
/** * 接收一条cmd * return cmd buffer on success or null on failure */ public function receive() { $res_body = $this->_connection->receive(); if (null != $res_body) { // 看看是否为标准错误包 $cmd_type = BigpipeFrame::get_command_type($res_body); if (BStompFrameType::ERROR == $cmd_type) { $recv_cmd = new BStompErrorFrame(); if ($recv_cmd->load($res_body)) { BigpipeLog::warning("[receive error ack frame][%s][error_code:%d]", $recv_cmd->error_message, $recv_cmd->error_no); } return null; } // end of 解析error frame } return $res_body; }