|
|
@ -22,19 +22,25 @@ class Consumer extends Command |
|
|
|
public function handle() |
|
|
|
{ |
|
|
|
$time = -microtime(true); |
|
|
|
$line = fn(string $string) => $string.\PHP_EOL; |
|
|
|
|
|
|
|
$handler = function (ConsumableMessage $message, AMQPMessage $otherMessage) use ($line) { |
|
|
|
echo $line($body = $message->getMessageBody()); |
|
|
|
|
|
|
|
$handler = function (ConsumableMessage $message, AMQPMessage $otherMessage) use (&$counter) { |
|
|
|
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, |
|
|
|
}; |
|
|
|
if (\str_contains($body, "finish")) { |
|
|
|
echo $line("finish"); |
|
|
|
$message->ack(); |
|
|
|
} catch (Throwable) { |
|
|
|
$message->nack(); |
|
|
|
$otherMessage->getChannel()->getConnection()->close(); |
|
|
|
} elseif (\str_contains($body, "requeue")) { |
|
|
|
echo $line("requeue"); |
|
|
|
$message->reject(); |
|
|
|
} else { |
|
|
|
echo $line("ack"); |
|
|
|
$message->ack(); |
|
|
|
} |
|
|
|
} catch (Throwable $e) { |
|
|
|
echo $line($e->getMessage()); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|