public function actionSend2()
 {
     set_time_limit(3);
     $loop = \React\EventLoop\Factory::create();
     $factory = new \React\Stomp\Factory($loop);
     $client = $factory->createClient(array('vhost' => '/', 'login' => 'guest', 'passcode' => 'guest'));
     $client->connect()->then(function ($client) use($loop) {
         $client->subscribe('/topic/test', function ($frame) {
             echo "Message received: {$frame->body}\n";
         });
         $loop->addPeriodicTimer(1, function () use($client) {
             $client->send('/topic/test', 'test message');
         });
     });
     $loop->run();
     return true;
 }
예제 #2
0
파일: basic.php 프로젝트: uuling/stomp
<?php

require __DIR__ . '/../vendor/autoload.php';
$conf = (require __DIR__ . '/config/probe.php');
$loop = React\EventLoop\Factory::create();
$factory = new React\Stomp\Factory($loop);
$client = $factory->createClient($conf);
$client->connect()->then(function ($client) use($loop) {
    $client->subscribe('/topic/foo', function ($frame) {
        echo "Message received: {$frame->body}\n";
    });
    $loop->addPeriodicTimer(1, function () use($client) {
        $client->send('/topic/foo', 'le message');
    });
}, function (\Exception $e) {
    echo sprintf("Could not connect: %s\n", $e->getMessage());
});
$loop->run();
예제 #3
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$factory = new React\Stomp\Factory($loop);
$client = $factory->createClient();
$client->connect()->then(function ($client) use($loop) {
    $prevMessageCount = 0;
    $messageCount = 0;
    $client->subscribe('/topic/foo', function ($frame) use(&$messageCount) {
        $messageCount++;
    });
    $loop->addPeriodicTimer(1, function () use(&$prevMessageCount, &$messageCount) {
        $diff = $messageCount - $prevMessageCount;
        echo "Received this second: {$diff}\n";
        $prevMessageCount = $messageCount;
    });
});
$loop->run();