Exemplo n.º 1
0
 /**
  * Tests Stomp->abort()
  */
 public function testAbort()
 {
     $this->Stomp->setReadTimeout(1);
     if (!$this->Stomp->isConnected()) {
         $this->Stomp->connect();
     }
     $this->Stomp->begin("tx1");
     $this->assertTrue($this->Stomp->send($this->queue, 'testSend', array("transaction" => "tx1")));
     $this->Stomp->abort("tx1");
     $this->Stomp->subscribe($this->queue);
     $frame = $this->Stomp->readFrame();
     $this->assertFalse($frame);
     $this->Stomp->unsubscribe($this->queue);
     $this->Stomp->disconnect();
 }
Exemplo n.º 2
0
// include a library
use FuseSource\Stomp\Stomp;
// make a connection
$con = new Stomp("tcp://localhost:61613");
// connect
$con->connect();
$con->setReadTimeout(1);
// subscribe to the queue
$con->subscribe("/queue/transactions", array('ack' => 'client', 'activemq.prefetchSize' => 1));
// try to send some messages
$con->begin("tx1");
for ($i = 1; $i < 3; $i++) {
    $con->send("/queue/transactions", $i, array("transaction" => "tx1"));
}
// if we abort transaction, messages will not be sent
$con->abort("tx1");
// now send some messages for real
$con->begin("tx2");
echo "Sent messages {\n";
for ($i = 1; $i < 5; $i++) {
    echo "\t{$i}\n";
    $con->send("/queue/transactions", $i, array("transaction" => "tx2"));
}
echo "}\n";
// they will be available for consumers after commit
$con->commit("tx2");
// try to receive some messages
$con->begin("tx3");
$messages = array();
for ($i = 1; $i < 3; $i++) {
    $msg = $con->readFrame();