Browse Source

second commit

mohammad
Mohammad Akbari 3 years ago
parent
commit
10a19b7478
Signed by: akbarjimi GPG Key ID: 55726AEFECE5E683
  1. 26
      app/Console/Commands/Consumer.php
  2. 5
      app/Console/Commands/Publisher.php
  3. 6
      routes/web.php

26
app/Console/Commands/Consumer.php

@ -22,24 +22,20 @@ class Consumer extends Command
public function handle()
{
$time = -microtime(true);
echo PHP_EOL;
$handler = function (ConsumableMessage $message, AMQPMessage $otherMessage) use (&$counter) {
$m = $otherMessage->getBody();
echo PHP_EOL;
echo PHP_EOL;
dump(\strcmp($m, "finish"), $m, "finish");
if (\strcmp($m, "finish") === 0) {
try {
echo "HERE";
echo PHP_EOL;
$otherMessage->getChannel()->getConnection()->close();
} catch (Throwable) {
echo "WHOOPS";
echo PHP_EOL;
}
echo $body = $message->getMessageBody();
echo \PHP_EOL;
try {
return match ($body) {
\strcmp($body, "finish") === 0 => $otherMessage->getChannel()->close(),
\strcmp($body, "requeue") === 0 => $message->nack(),
default => $body,
};
$message->ack();
} catch (Throwable) {
$message->nack();
}
$message->ack();
};
$consume = [

5
app/Console/Commands/Publisher.php

@ -33,7 +33,8 @@ class Publisher extends Command
echo PHP_EOL;
for ($index = 1; $index <= (int) $this->option('count'); $index++) {
$payload = rand(1,100) <= 20 ? "finish" : "Message #$index";
$chance = rand(1, 100);
$payload = $chance <= 20 ? "finish #$index" : ($chance <= 40 ? "requeue #$index" : "Message #$index");
$message = [
'content_type' => 'text/plain',
@ -78,7 +79,7 @@ class Publisher extends Command
];
$message = new ProducibleMessage(
message: json_encode($payload),
message: $payload,
properties: $publish + $message,
);

6
routes/web.php

@ -3,12 +3,6 @@
use Illuminate\Support\Facades\Route;
Route::get('/lab', function () {
$m = (string) "finish";
$s = (string) $m;
dd($m, $s);
$message_delivery = [
1,
2,

Loading…
Cancel
Save