本文整理匯總了PHP中Header::set_messageType方法的典型用法代碼示例。如果您正苦於以下問題:PHP Header::set_messageType方法的具體用法?PHP Header::set_messageType怎麽用?PHP Header::set_messageType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Header
的用法示例。
在下文中一共展示了Header::set_messageType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: publish
/**
* @param $topic
* @param $type
* @param $msg
* @throws \Exception
* @return bool
*/
public function publish($topic, $type, $msg)
{
if (!$this->connected) {
$this->connect();
}
if (!$this->greeted) {
$this->greet();
}
if (!$this->jsonEnable) {
$msgEntity = new \StringMessage();
$msgHeader = new \Header();
$msgHeader->set_groupId($this->group);
$msgHeader->set_commit(true);
$msgHeader->set_deliverLimit(100);
$msgHeader->set_expiredTime(-1);
$msgHeader->set_fly(false);
$msgHeader->set_topic($topic);
$guid = new Guid();
$msgHeader->set_messageId($guid->toString());
$msgHeader->set_messageType($type);
$msgEntity->set_header($msgHeader);
$msgEntity->set_body($msg);
$send = $msgEntity->SerializeToString();
if (function_exists('kiteq_request')) {
list($data, $type) = kiteq_request($this->conn, $send, self::CMD_STRING_MESSAGE);
} else {
// 發送
$this->innerSend($send, self::CMD_STRING_MESSAGE);
// 接受
list($type, $data) = $this->innerGet();
}
if ($type != self::CMD_MESSAGE_STORE_ACK) {
throw new \Exception("kiteq 驗證錯誤 MessageType {$type}");
}
$ack = new \MessageStoreAck();
$ack->ParseFromString($data);
if ($ack->getStatus() == false) {
throw new \Exception($ack->getFeedback());
}
return $ack->getStatus();
} else {
$msgEntity = array();
$msgHeader = array('groupId' => $this->group, 'commit' => true, 'deliverLimit' => 100, 'expiredTime' => -1, 'fly' => false, 'topic' => $topic, 'messageId' => uniqid(), 'messageType' => $type);
$msgEntity['header'] = $msgHeader;
$msgEntity['body'] = $msg;
$send = json_encode($msgEntity);
if (function_exists('kiteq_request')) {
list($data, $type) = kiteq_request($this->conn, $send, self::CMD_STRING_MESSAGE | 0x80);
} else {
// 發送
$this->innerSend($send, self::CMD_STRING_MESSAGE | 0x80);
// 接受
list($type, $data) = $this->innerGet();
}
if ($type != self::CMD_MESSAGE_STORE_ACK) {
throw new \Exception("kiteq 驗證錯誤 MessageType {$type}");
}
$ack = json_decode($data, true);
if ($ack->getStatus() == false) {
throw new \Exception($ack->getFeedback());
}
return $ack->getStatus();
}
}