Example #1
0
 /**
  * Tests Stomp->unsubscribe()
  */
 public function testUnsubscribe()
 {
     if (!$this->Stomp->isConnected()) {
         $this->Stomp->connect();
     }
     $this->Stomp->subscribe($this->queue);
     $this->assertTrue($this->Stomp->unsubscribe($this->queue));
 }
Example #2
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();
Example #3
0
 protected function subscribe()
 {
     $consumer = new Stomp($this->broker);
     $consumer->sync = false;
     $consumer->clientId = "test";
     $consumer->connect("system", "manager");
     $consumer->subscribe($this->topic);
     $consumer->unsubscribe($this->topic);
     $consumer->disconnect();
 }
Example #4
0
 protected function subscribe()
 {
     $consumer = new Stomp($this->broker);
     $consumer->sync = true;
     $consumer->clientId = "test";
     $consumer->connect($this->login, $this->password);
     $consumer->subscribe($this->topic, array('persistent' => 'true'));
     $consumer->unsubscribe($this->topic);
     $consumer->disconnect();
 }