public function __construct() { parent::__construct(MetaAgentFrameType::ACK_UNINIT_API); // 定义fields $this->_fields = array('status' => 'int32'); }
/** * 检查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; }
public function __construct() { parent::__construct(BStompFrameType::MESSAGE); // 定义fields // bigpipe中id的定义是uint64,php暂时定义为int64 $this->_fields = array('priority' => 'int16', 'persistent' => 'int16', 'no_dedupe' => 'int32', 'timeout' => 'int64', 'destination' => 'string', 'session_id' => 'string', 'subscribe_id' => 'string', 'receipt_id' => 'string', 'session_message_id' => 'int64', 'topic_message_id' => 'int64', 'global_message_id' => 'int64', 'cur_checksum' => 'int64', 'last_checksum' => 'int64', 'message_body' => 'blob'); $this->_fields_restriction = array('destination' => BigpipeCommonDefine::MAX_SIZE_NAME, 'session_id' => BigpipeCommonDefine::MAX_SIZE_NAME, 'subscribe_id' => BigpipeCommonDefine::MAX_SIZE_NAME, 'receipt_id' => BigpipeCommonDefine::MAX_SIZE_RECEIPT_ID); }
/** * 接收一条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; }