throw new InvalidArgumentException('Failure limit must be greater than zero.'
);
} } public function onMessageFailed(WorkerMessageFailedEvent
$event): void
{ ++
$this->failedMessages;
} public function onWorkerRunning(WorkerRunningEvent
$event): void
{ if (!
$event->
isWorkerIdle() &&
$this->failedMessages >=
$this->maximumNumberOfFailures
) { $this->failedMessages = 0;
$event->
getWorker()->
stop();
$this->logger?->
info('Worker stopped due to limit of {count} failed message(s) is reached',
['count' =>
$this->maximumNumberOfFailures
]);
} } public static function getSubscribedEvents(): array
{ return [ WorkerMessageFailedEvent::
class => 'onMessageFailed',