private function _gen_connected_frame() { $ack = new BStompConnectedFrame(); $ack->session_id = 'id-for-unittest'; $ack->session_message_id = 9527; $ack->store(); $good = $ack->buffer(); // bad frame $bad_ack = new BStompReceiptFrame(); $bad_ack->receipt_id = 'bad-id'; $bad_ack->store(); $bad = $bad_ack->buffer(); return array('good' => $good, 'bad' => $bad); }
private function _get_unsub_response() { $ack = new BStompReceiptFrame(); $ack->receipt_id = 'unittest-receipt-id'; $ack->store(); $good = $ack->buffer(); $ack->receipt_id = 'wrong-receipt-id'; $ack->store(); $bad = $ack->buffer(); $unsub_ack = array('good' => $good, 'bad' => $bad); return $unsub_ack; }
/** * 取消订阅 */ private function _unsubscribe() { if (!$this->_is_subscribed) { return true; // 取消成功 } // 填充取消订阅包 $cmd = new BStompUnsubscribeFrame(); $cmd->destination = $this->_stripe['stripe_name']; // $cmd->subscribe_id = null; 目前无用 $cmd->receipt_id = isset($this->unittest) ? 'unittest-receipt-id' : BigpipeUtilities::gen_receipt_id(); if (!$this->_stomp_adapter->send($cmd)) { BigpipeLog::warning('[%s:%u][%s][send error]', __FILE__, __LINE__, __FUNCTION__); return false; } // 接收RECEIPT $res_body = $this->_stomp_adapter->receive(); if (null === $res_body) { BigpipeLog::warning('[%s:%u][%s][receive error]', __FILE__, __LINE__, __FUNCTION__); return false; } // parse RECEIPT $ack = new BStompReceiptFrame(); if (!$ack->load($res_body)) { BigpipeLog::warning('[%s:%u][%s][load receipt error][cmd_type:%d][err_msg:%s]', __FILE__, __LINE__, __FUNCTION__, $ack->command_type, $ack->last_error_message()); return false; } // 检查取消订阅是否成功 if ($ack->receipt_id != $cmd->receipt_id) { BigpipeLog::warning('[%s:%u][%s][error receipt id][send:%u][recv:%u]', __FILE__, __LINE__, __FUNCTION__, $cmd->receipt_id, $ack->receipt_id); return false; } $this->_is_subscribed = false; return true; }