コード例 #1
0
 public function testConnectAuth()
 {
     $loop = Factory::create();
     $loop->addTimer(5, function () {
         throw new TimeoutException();
     });
     $client = new Client($loop, ["user" => "testuser", "password" => "testpassword", "vhost" => "testvhost"]);
     $client->connect()->then(function (Client $client) {
         return $client->disconnect();
     })->then(function () use($loop) {
         $loop->stop();
     });
     $loop->run();
 }
コード例 #2
0
ファイル: AsyncClientTest.php プロジェクト: mabrahamde/bunny
 public function testDisconnectWithBufferedMessages()
 {
     $loop = Factory::create();
     $loop->addTimer(5, function () {
         throw new TimeoutException();
     });
     $processed = 0;
     $client = new Client($loop);
     $client->connect()->then(function (Client $client) {
         return $client->channel();
     })->then(function (Channel $channel) use($client, $loop, &$processed) {
         return Promise\all([$channel->qos(0, 1000), $channel->queueDeclare("disconnect_test"), $channel->consume(function (Message $message, Channel $channel) use($client, $loop, &$processed) {
             $channel->ack($message);
             ++$processed;
             $client->disconnect()->then(function () use($loop) {
                 $loop->stop();
             });
         }, "disconnect_test"), $channel->publish(".", [], "", "disconnect_test"), $channel->publish(".", [], "", "disconnect_test"), $channel->publish(".", [], "", "disconnect_test")]);
     });
     $loop->run();
     // all messages should be processed
     $this->assertEquals(1, $processed);
 }
コード例 #3
0
ファイル: consumer_async.php プロジェクト: mabrahamde/bunny
namespace Bunny;

use Bunny\Async\Client;
use React\Promise;
require_once __DIR__ . "/../vendor/autoload.php";
$c = new Client();
$c->connect()->then(function (Client $c) {
    return $c->channel();
})->then(function (Channel $ch) {
    return Promise\all([$ch, $ch->queueDeclare("bench_queue"), $ch->exchangeDeclare("bench_exchange"), $ch->queueBind("bench_queue", "bench_exchange")]);
})->then(function ($r) {
    /** @var Channel $ch */
    $ch = $r[0];
    $t = null;
    $count = 0;
    return $ch->consume(function (Message $msg, Channel $ch, Client $c) use(&$t, &$count) {
        if ($t === null) {
            $t = microtime(true);
        }
        if ($msg->content === "quit") {
            printf("Pid: %s, Count: %s, Time: %.4f\n", getmypid(), $count, microtime(true) - $t);
            $c->disconnect()->then(function () use($c) {
                $c->stop();
            });
        } else {
            ++$count;
        }
    }, "bench_queue", "", false, true);
});
$c->run();
コード例 #4
0
ファイル: producer_async.php プロジェクト: mabrahamde/bunny
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza
EOT;
$time = microtime(true);
$max = isset($argv[1]) ? (int) $argv[1] : 1;
$c->connect()->then(function (Client $c) {
    return $c->channel();
})->then(function (Channel $ch) {
    return Promise\all([$ch, $ch->queueDeclare("bench_queue"), $ch->exchangeDeclare("bench_exchange"), $ch->queueBind("bench_queue", "bench_exchange")]);
})->then(function ($r) use($body, &$time, &$max) {
    /** @var Channel $ch */
    $ch = $r[0];
    $promises = [];
    for ($i = 0; $i < $max; $i++) {
        $promises[] = $ch->publish($body, [], "bench_exchange");
    }
    $promises[] = $ch->publish("quit", [], "bench_exchange");
    return Promise\all($promises);
})->then(function () use($c) {
    return $c->disconnect();
})->then(function () use($c, &$time) {
    echo microtime(true) - $time, "\n";
    $c->stop();
});
$c->run();