CakeFest 2024: The Official CakePHP Conference

Stomp::subscribe

stomp_subscribe

(PECL stomp >= 0.1.0)

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

Descrição

Estilo orientado a objetos (method):

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

Estilo procedural:

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

Registers to listen to a given destination.

Parâmetros

link

Somente no estilo procedural: O identificador do link stomp retornado por stomp_connect().

destination

Destination to subscribe to.

headers

Um array associativo contendo os cabeçalhos adicionais (exemplo: receipt).

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Exemplos

See stomp_ack().

Notas

Dica

O Stomp é naturalmente assíncrono. Comunicação síncrona pode ser implementada adicionando um cabeçalho receipt. Isso fará com que os métodos não retornem nada até que o servidor confirme o recebimento da mensagem ou até que o tempo limite de leitura seja atingido.

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