Skip to content

Instantly share code, notes, and snippets.

@Nixes
Last active April 20, 2021 07:12
Show Gist options
  • Save Nixes/a675ccaef7c83185e2c4798c0de3b965 to your computer and use it in GitHub Desktop.
Save Nixes/a675ccaef7c83185e2c4798c0de3b965 to your computer and use it in GitHub Desktop.
symfony event handler that runs when a message has been rejected (all retries attempted and failed)
<?php
class MessageOnRejectionSubscriber implements EventSubscriberInterface {
public function onMessageFailed(WorkerMessageFailedEvent $event) {
// return early if there is still more retrying to do
if ($event->willRetry()) {
return;
}
$envelope = $event->getEnvelope();
echo "Message failure caught by ".self::class."\n";
}
public static function getSubscribedEvents() {
return [
WorkerMessageFailedEvent::class => ['onMessageFailed', -100],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment