<?php
namespace App\EventSubscriber;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\Exception\RejectRedeliveredMessageException;
final class AppWorkerSubscriber implements EventSubscriberInterface
{
private LoggerInterface $logger;
public function __construct(LoggerInterface $slackLogger)
{
$this->logger = $slackLogger;
}
public static function getSubscribedEvents(): array
{
return [
WorkerMessageFailedEvent::class => 'onMessageFailed'
];
}
public function onMessageFailed(WorkerMessageFailedEvent $event): void
{
$exception = $event->getThrowable();
if (!$exception instanceof RejectRedeliveredMessageException) {
$this->logger->critical($exception->getMessage(), [
'exception' => $exception,
'receiver' => $event->getReceiverName()
]);
}
}
}