コード例 #1
0
ファイル: StompTest.php プロジェクト: vasiliyyudin/stomp-php
 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();
 }
コード例 #2
0
$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++) {
    $msg = $con->readFrame();
    $con->ack($msg, 'tx4');
    array_push($messages, $msg);
}
// commit all acks
$con->commit('tx4');
echo "Processed messages {\n";
foreach ($messages as $msg) {
    echo "\t{$msg->body}\n";
}
echo "}\n";
//ensure there are no more messages in the queue
$frame = $con->readFrame();
if ($frame === false) {
    echo "No more messages in the queue\n";
} else {
    echo "Warning: some messages still in the queue: {$frame}\n";
}
// disconnect
$con->disconnect();
コード例 #3
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();
 }
コード例 #4
0
ファイル: ASyncTest.php プロジェクト: phpwutz/stomp-php
 /**
  * Cleans up the environment after running a test.
  */
 protected function tearDown()
 {
     $this->Stomp->disconnect();
     $this->Stomp = null;
     parent::tearDown();
 }
コード例 #5
0
ファイル: durable.php プロジェクト: phpwutz/stomp-php
// 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);
}
// this message will never be seen, since no durable subscriber is present
$producer->send('/topic/test', 'test-3');
$consumer->disconnect();
$producer->disconnect();