PHP 8.1.28 Released!

Stomp::subscribe

stomp_subscribe

(PECL stomp >= 0.1.0)

Stomp::subscribe -- stomp_subscribeRegisters to listen to a given destination

Descrizione

Stile orientato agli oggetti (method):

public Stomp::subscribe(string $destination, array $headers = ?): bool

Stile procedurale:

stomp_subscribe(resource $link, string $destination, array $headers = ?): bool

Registers to listen to a given destination.

Elenco dei parametri

link

Solo stile procedurale: l'identificatore di connessione stomp restituito da stomp_connect().

destination

Destination to subscribe to.

headers

Array associativo che contiene le intestazioni addizionali (per esempio: receipt).

Valori restituiti

Restituisce true in caso di successo, false in caso di fallimento.

Esempi

See stomp_ack().

Note

Suggerimento

Stomp è intrinsecamente asincrono. Le comunicazioni sincrone possono essere implementate aggiungendo un'intestazione di ricevuta. Questo fa sì che i metodi non restituiscono nulla finché il server non abbia confermato la ricezione del messaggio o al raggiungimento del timeout.

add a note

User Contributed Notes 1 note

up
-1
holycd
6 years ago
Using Topics from PHP over Stomp
$clientId = 'test:dev';
$topic = '/topic/perm.user';

try {
$stomp = new Stomp('tcp://localhost:61613','system','manager', array('client-id'=> $clientId ));
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}

$isSubscribe = $stomp->subscribe($topic);

while($isSubscribe){
if ($stomp->hasFrame()) {
$frame = $stomp->readFrame();
if ($frame != NULL) {
print "Received: " . $frame->body . " - time now is " . date("Y-m-d H:i:s"). "\n";
// $stomp->ack($frame);
}
// sleep(1);
}
else {
print "No frames to read\n";
}
}
if($isSubscribe){
$stomp->unsubscribe($topic);
unset($stomp);
}

Can not receive the topic frame
To Top