/** * 生成ack响应供测试程序使用 * @return ack响应集供test case选择 */ private function _gen_ack_response($subject) { $ack = new BStompAckFrame(); $ack->status = BStompIdAckType::TOPIC_ID; $ack->ack_type = BStompFrameType::ACK; $ack->session_message_id = TestUtilities::get_private_var($subject, '_session_msg_id') + 1; $this->assertFalse(false === $ack->session_message_id); $ack->topic_message_id = 369; $ack->global_message_id = 7659; $ack->delay_time = 0; $ack->destination = 'unknown'; $ack->receipt_id = 'fake-receipt-id'; $ack->store(); $good_ack = $ack->buffer(); $orig_smid = $ack->session_message_id; $ack->session_message_id = $orig_smid + 10; $ack->store(); $bad_session = $ack->buffer(); $ack->session_message_id = $orig_smid; $ack->receipt_id = BigpipeUtilities::get_uid(); $ack->store(); $bad_receipt = $ack->buffer(); $res_arr = array('good' => $good_ack, 'bad_session' => $bad_session, 'bad_receipt' => $bad_receipt, 'error_body' => 'error'); return $res_arr; }
/** * 接收返回消息, 判断发布是否成功 * @return BigpipePubResult on success or false on failure */ private function _check_ack($receipt_id, &$send_result) { // 接收CONNECTED $res_body = $this->_stomp_adapter->receive(); if (null === $res_body) { return false; } // parse ACK $ack = new BStompAckFrame(); if (!$ack->load($res_body)) { BigpipeLog::warning('[stomp parse ack frame error][cmd_type:%d][err_msg:]', $ack->command_type, $ack->last_error_message()); return false; } if ($ack->session_message_id != $this->_session_msg_id) { BigpipeLog::warning('[check session message id error][send:%u][ack:%u]', $this->_session_msg_id, $ack->session_message_id); return false; } if ($ack->receipt_id != $receipt_id) { BigpipeLog::warning('[check receipt id error][send:%u][ack:%u]', $receipt_id, $ack->receipt_id); return false; } // 填充result $send_result = new BigpipePubResult(); $send_result->error_no = $ack->status; $send_result->pipelet_id = $this->_pipelet_id; $send_result->pipelet_msg_id = $ack->topic_message_id; $send_result->session_msg_id = $ack->session_message_id; return $send_result; }