通过 Stomp 使用 PHP 的主题
$clientId = 'test:dev';
$topic = '/topic/perm.user';
try {
$stomp = new Stomp('tcp://localhost:61613','system','manager', array('client-id'=> $clientId ));
} catch(StompException $e) {
die('连接失败:' . $e->getMessage());
}
$isSubscribe = $stomp->subscribe($topic);
while($isSubscribe){
if ($stomp->hasFrame()) {
$frame = $stomp->readFrame();
if ($frame != NULL) {
print "已接收: " . $frame->body . " - 当前时间是 " . date("Y-m-d H:i:s"). "\n";
// $stomp->ack($frame);
}
// sleep(1);
}
else {
print "没有帧可读取\n";
}
}
if($isSubscribe){
$stomp->unsubscribe($topic);
unset($stomp);
}
无法接收主题帧