本文整理汇总了PHP中Header::set_topic方法的典型用法代码示例。如果您正苦于以下问题:PHP Header::set_topic方法的具体用法?PHP Header::set_topic怎么用?PHP Header::set_topic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Header
的用法示例。
在下文中一共展示了Header::set_topic方法的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();
}
}