示例#1
0
 /**
  * Tests Stomp->connect(), send() and subscribe() in order.
  */
 public function testSyncSub()
 {
     $this->assertTrue($this->Stomp->connect());
     $this->assertTrue($this->Stomp->subscribe('/queue/test'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 1'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 2'));
     $this->Stomp->setReadTimeout(5);
     $frame = $this->Stomp->readFrame();
     $this->assertEquals('test 1', $frame->body, 'test 1 not received!');
     $this->Stomp->ack($frame);
     $frame = $this->Stomp->readFrame();
     $this->assertEquals('test 2', $frame->body, 'test 2 not received!');
     $this->Stomp->ack($frame);
 }
示例#2
0
 /**
  * Tests Stomp->hasFrameToRead()
  *
  */
 public function testHasFrameToRead()
 {
     if (!$this->Stomp->isConnected()) {
         $this->Stomp->connect();
     }
     $this->Stomp->setReadTimeout(5);
     $this->assertFalse($this->Stomp->hasFrameToRead(), 'Has frame to read when non expected');
     $this->Stomp->send($this->queue, 'testHasFrameToRead');
     $this->Stomp->subscribe($this->queue, array('ack' => 'client', 'activemq.prefetchSize' => 1));
     $this->assertTrue($this->Stomp->hasFrameToRead(), 'Did not have frame to read when expected');
     $frame = $this->Stomp->readFrame();
     $this->assertTrue($frame instanceof Fusesource\Stomp\Frame, 'Frame expected');
     $this->Stomp->ack($frame);
     $this->Stomp->disconnect();
     $this->Stomp->setReadTimeout(60);
 }
示例#3
0
 *
 * 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 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"));
示例#4
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);
     $frame = $consumer2->readFrame();
     $this->assertEquals($frame->body, "test message");
     if ($frame != null) {
         $consumer2->ack($frame);
     }
     $consumer2->disconnect();
 }
示例#5
0
 *
 * 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 FuseSource\Stomp\Stomp;
// create a producer
$producer = new Stomp("tcp://localhost:61613");
// create a consumer
$consumer = new Stomp("tcp://localhost:61613");
$consumer->setReadTimeout(1);
// set clientId on a consumer to make it durable
$consumer->clientId = "test";
// connect
$producer->connect();
$consumer->connect();
// subscribe to the topic
$consumer->subscribe("/topic/test");
sleep(1);
// send a message to the topic
$producer->send("/topic/test", "test", array('persistent' => 'true'));
echo "Message 'test' sent to topic\n";
// receive a message from the topic
$msg = $consumer->readFrame();
// do what you want with the message
if ($msg != null) {
示例#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();
 }