|
11 | 11 | $loop = Factory::create();
|
12 | 12 | $config = require 'resolve_config.php';
|
13 | 13 |
|
| 14 | +$height = 0; |
| 15 | +$length = 0; |
| 16 | +$queues = []; |
| 17 | + |
14 | 18 | $client = AsyncClient::create($loop, $config['baseUrl'], $config['username'], $config['password']);
|
15 |
| -$queues = $client->queues(1)->filter(function (QueueInterface $queue) { |
| 19 | +$client->queues(1)->filter(function (QueueInterface $queue) { |
16 | 20 | return strpos($queue->name(), 'amq.gen') !== 0;
|
17 |
| -})->subscribe(new CallbackObserver(function (QueueInterface $queue) { |
18 |
| - echo $queue->name(), ': ', $queue->messageStats()->deliverDetails()->rate(), PHP_EOL; |
| 21 | +})->subscribe(new CallbackObserver(function (QueueInterface $queue) use (&$queues) { |
| 22 | + $queues[$queue->name()] = $queue->messageStats()->deliverDetails()->rate(); |
19 | 23 | }));
|
20 | 24 |
|
| 25 | +$loop->addPeriodicTimer(1, function () use (&$height, &$length, &$queues) { |
| 26 | + for ($i = 0; $i < $height; $i++) { |
| 27 | + echo "\033[1A"; |
| 28 | + } |
| 29 | + |
| 30 | + if ($height < count($queues)) { |
| 31 | + $height = count($queues); |
| 32 | + } |
| 33 | + |
| 34 | + ksort($queues); |
| 35 | + |
| 36 | + $i = 0; |
| 37 | + foreach ($queues as $key => $value) { |
| 38 | + $line = $key . ': ' . $value . ' sec'; |
| 39 | + if ($length < strlen($line)) { |
| 40 | + $length = strlen($line); |
| 41 | + } |
| 42 | + $line = str_pad($line, $length, ' '); |
| 43 | + echo $line, PHP_EOL; |
| 44 | + $i++; |
| 45 | + } |
| 46 | + for (; $i < $height; $i++) { |
| 47 | + echo "\r"; |
| 48 | + } |
| 49 | + |
| 50 | + $queues = []; |
| 51 | +}); |
| 52 | + |
21 | 53 | $loop->run();
|
0 commit comments