Esempio n. 1
0
 public function testAbortTransaction()
 {
     $this->assertTrue($this->Stomp->connect());
     $this->assertTrue($this->Stomp->begin('my-id'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test t-id', array('transaction' => 'my-id')));
     $this->assertTrue($this->Stomp->abort('my-id'));
     $this->assertTrue($this->Stomp->subscribe('/queue/test'));
     $this->Stomp->getConnection()->setReadTimeout(array(1, 0));
     $frame = $this->Stomp->readFrame();
     $this->assertFalse($frame);
 }
Esempio n. 2
0
 /**
  * Tests Stomp->connect(), send(), and subscribe() - out of order. the messages should be received in FIFO order.
  */
 public function testAsyncSub()
 {
     $this->assertTrue($this->Stomp->connect());
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 1'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 2'));
     $this->assertTrue($this->Stomp->subscribe('/queue/test'));
     $frame = $this->Stomp->readFrame();
     $this->assertEquals($frame->body, 'test 1', 'test 1 was not received!');
     $this->Stomp->ack($frame);
     $frame = $this->Stomp->readFrame();
     $this->assertEquals($frame->body, 'test 2', 'test 2 was not received!');
     $this->Stomp->ack($frame);
 }
Esempio n. 3
0
 protected function consume()
 {
     $consumer2 = new Stomp($this->broker);
     $consumer2->sync = false;
     $consumer2->clientId = 'test';
     $consumer2->setReadTimeout(1);
     $consumer2->connect('system', 'manager');
     $consumer2->subscribe($this->topic, null, null, true);
     $frame = $consumer2->readFrame();
     $this->assertEquals($frame->body, 'test message');
     if ($frame != null) {
         $consumer2->ack($frame);
     }
     // yes, that's active mq! you must unsub two times...
     // http://mail-archives.apache.org/mod_mbox/activemq-dev/201205.mbox/raw/
     //        %3C634996273.21688.1336051731428.JavaMail.tomcat@hel.zones.apache.org%3E/
     $consumer2->unsubscribe($this->topic);
     // that took me some time...
     $consumer2->unsubscribe($this->topic, null, null, true);
     $consumer2->disconnect();
 }
Esempio n. 4
0
$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();
    array_push($messages, $msg);
    $con->ack($msg, 'tx3');
}
// of we abort transaction, we will "rollback" out acks
$con->abort('tx3');
$con->begin('tx4');
// so we need to ack received messages again
// before we can receive more (prefetch = 1)
if (count($messages) != 0) {
    foreach ($messages as $msg) {
        $con->ack($msg, 'tx4');
    }
}
// now receive more messages
for ($i = 1; $i < 3; $i++) {
Esempio n. 5
0
 * limitations under the License.
 */
// include a library
use Stomp\Stomp;
use Stomp\Message\Map;
// make a connection
$con = new Stomp('tcp://localhost:61613');
// connect
$con->connect();
// send a message to the queue
$body = array('city' => 'Belgrade', 'name' => 'Dejan');
$header = array();
$header['transformation'] = 'jms-map-json';
$mapMessage = new Map($body, $header);
$con->send('/queue/test', $mapMessage);
echo 'Sending array: ';
print_r($body);
$con->subscribe('/queue/test', array('transformation' => 'jms-map-json'));
/** @var Map $msg */
$msg = $con->readFrame();
// extract
if ($msg != null) {
    echo 'Received array: ';
    print_r($msg->map);
    // mark the message as received in the queue
    $con->ack($msg);
} else {
    echo "Failed to receive a message\n";
}
// disconnect
$con->disconnect();
Esempio n. 6
0
 protected function consume()
 {
     $consumer2 = new Stomp($this->broker);
     $consumer2->sync = true;
     $consumer2->clientId = 'test';
     $consumer2->setReadTimeout(1);
     $consumer2->connect($this->login, $this->password);
     $consumer2->subscribe($this->topic, array('persistent' => 'true'));
     $frame = $consumer2->readFrame();
     $this->assertEquals($frame->body, 'test message');
     if ($frame != null) {
         $consumer2->ack($frame);
     }
     $consumer2->disconnect();
 }
Esempio n. 7
0
}
// disconnect durable consumer
$consumer->unsubscribe('/topic/test');
$consumer->disconnect();
echo "Disconnecting consumer\n";
// send a message while consumer is disconnected
$producer->send('/topic/test', 'test-2');
echo "Message 'test-2' sent to topic\n";
// reconnect the durable consumer
$consumer = new Stomp('tcp://localhost:61613');
$consumer->clientId = 'test';
$consumer->connect('admin', 'password');
$consumer->subscribe('/topic/test', null, true, true);
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
if ($consumer->getProtocol() instanceof \Stomp\Protocol\ActiveMq) {
    // activeMq Way
    $consumer->unsubscribe('/topic/test');
    $consumer->unsubscribe('/topic/test', null, true, true);
} else {
    // default (apollo way)
    $consumer->unsubscribe('/topic/test', null, true, true);