Esempio n. 1
0
} else {
    echo "Failed to receive a message\n";
}
sleep(1);
// disconnect durable consumer
$consumer->unsubscribe("/topic/test");
$consumer->disconnect();
echo "Disconnecting consumer\n";
// send a message while consumer is disconnected
// note: only persistent messages will be redelivered to the durable consumer
$producer->send("/topic/test", "test1", array('persistent' => 'true'));
echo "Message 'test1' sent to topic\n";
// reconnect the durable consumer
$consumer = new Stomp("tcp://localhost:61613");
$consumer->clientId = "test";
$consumer->connect();
$consumer->subscribe("/topic/test");
echo "Reconnecting consumer\n";
// receive a message from the topic
$msg = $consumer->readFrame();
// do what you want with the message
if ($msg != null) {
    echo "Message '{$msg->body}' received from topic\n";
    $consumer->ack($msg);
} else {
    echo "Failed to receive a message\n";
}
// disconnect
$consumer->unsubscribe("/topic/test");
$consumer->disconnect();
$producer->disconnect();