Skip to content

Improve exception handling together with Symfony's Messenger retry mechanism #427

Closed
@Toflar

Description

@Toflar

I'm using the retry feature of Symfony's Messenger component as documented here: https://symfony.com/doc/current/messenger.html#retries-failures

As for the purpose of this issue, let's imagine our message handler like this:

<?php

class FoobarMessageHandler implements MessageHandlerInterface
{
    public function __invoke(FoobarMessage $message): void
    {
         $this->someHttpClient->request(...);
    }
}

A good example would be that this service calls an external API which might be temporarily down. The cool thing about this is that I don't need to catch the exception and Symfony's configurable retry handling will automatically retry to process the message later on. In my case, that covers 99% of the use cases because it's usually just a temporary hickup like a connection timeout or what not. That's also the reason why I put it on a message queue in the first place: I want to ensure things are processed.

The issue I'm facing is that of course, the Sentry bundle still reports this exception. I then check the Sentry issue only to realize that it's already been dealt with because of the retry mechanism.

It would be fantastic if I'd only be informed about that issue when the max retry level was reached. Aka, when the message is put on the failure message queue.

Any ideas how to tackle this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions