// include a library require_once "Stomp.php"; // 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();
<?php // include a library require_once "Stomp.php"; // make a connection $con = new Stomp("tcp://localhost:61613"); // connect $con->connect(); // 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++) { $con->send("/queue/transactions", $i, array("transaction" => "tx2")); echo "\t{$i}\n"; } echo "}\n"; // they will be available for consumers after commit $con->commit("tx2");
$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 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++) { $msg = $con->readFrame(); $con->ack($msg, "tx4"); array_push($messages, $msg); } // commit all acks