diff --git a/app/Console/Commands/Consumer.php b/app/Console/Commands/Consumer.php index 858ccb3..19000d1 100644 --- a/app/Console/Commands/Consumer.php +++ b/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 = [ diff --git a/app/Console/Commands/Publisher.php b/app/Console/Commands/Publisher.php index 77af4f0..e262691 100644 --- a/app/Console/Commands/Publisher.php +++ b/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, ); diff --git a/routes/web.php b/routes/web.php index cf453ed..f21b255 100644 --- a/routes/web.php +++ b/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,