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);
 }
Beispiel #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);
 }
Beispiel #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();
 }
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// include a library
use 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";
 /**
  * Tests Stomp->connect()
  */
 public function testFailoverConnect()
 {
     $this->assertTrue($this->Stomp->connect());
 }
Beispiel #6
0
 public function testConnectOnApollo()
 {
     $this->assertTrue($this->client->connect('admin', 'password'), 'Expected reachable broker.');
     $this->assertInstanceOf('\\Stomp\\Protocol\\Apollo', $this->client->getProtocol(), 'Expected a Apollo broker.');
 }
Beispiel #7
0
 To successfully run this example, you must first start the broker with security enabled.
 You can do that by executing:
 $ ${ACTIVEMQ_HOME}/bin/activemq xbean:activemq-security.xml
 Then you can execute this example with:
 $ php security.php
*/
// include a library
use Stomp\Stomp;
use Stomp\Exception\StompException;
// make a connection
$con = new Stomp('tcp://localhost:61613');
// use sync operations
$con->sync = true;
// connect
try {
    $con->connect('dejan', 'test');
} catch (StompException $e) {
    echo "dejan cannot connect\n";
    echo $e->getMessage() . "\n";
}
$con->connect('guest', 'password');
// send a message to the queue
try {
    $con->send('/queue/test', 'test');
    echo "Guest sent message with body 'test'\n";
} catch (StompException $e) {
    echo "guest cannot send\n";
    echo $e->getMessage() . "\n";
}
// disconnect
$con->disconnect();
 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();
 }
Beispiel #9
0
    echo "Message '{$msg->body}' received from topic\n";
    $consumer->ack($msg);
} else {
    echo "Failed to receive a message\n";
}
// 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');
Beispiel #10
0
 /**
  * Tests Stomp->connect()
  */
 public function testFailoverConnect()
 {
     $this->assertTrue($this->Stomp->connect('admin', 'password'));
 }