New in Symfony 4.3: Messenger failure transport

Contributed by
Ryan Weaver
in #30970.

The Messenger component provides a retry mechanism for messages. In Symfony 4.3 we've improved this feature to add a "failure" transport, so that messages that fail on all their retries can be collected in one spot and retried later if wanted.

Consider the following configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
framework:
    messenger:
        failure_transport: failed

        transports:
            async:
                dsn: 'amqp://'
            failed:
                dsn: 'doctrine://default?queue_name=failed'

        routing:
            'App\Message\SmsNotification': async

In this setup, SmsNotification would be retried three times on the async transport and then finally sent to the failed transport. You can consume the failed transport like a normal transport, but you should handle and consume it by one of these new commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ php bin/console messenger:failed:show

  There are 3 messages waiting in the failed transport.

  ---  ---------------------------  -------------------  -----
  Id   Class                        Failed at            Error
  ---  ---------------------------  -------------------  -----
  217  App\Message\SmsNotification  2019-04-10 22:12:01  ...
  218  App\Message\SmsNotification  2019-04-10 22:12:00  ...
  219  App\Message\SmsNotification  2019-04-10 22:11:59  ...
  ---  ---------------------------  -------------------  -----

  // Run "messenger:failed:show {id} -vv" to see message details
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$ php bin/console messenger:failed:show 217

  There are 3 messages waiting in the failed transport.

  -----------  ---------------------------
  Class        App\Message\SmsNotification
  Message Id   217
  Failed at    2019-04-10 22:12:01
  Error        ...
  Error Class  Exception
  Transport    async
  -----------  ---------------------------

  Re-run command with "-vv" to see more message & error details.

  Run "messenger:failed:retry 217" to retry this message.
  Run "messenger:failed:purge 217" to delete it.

Comments

This looks great! Can you describe how to configure the

dsn: 'doctrine://default?queue_name=failed'

I'm not familiar with this syntax for doctrine.
Fantastic, thanks for this feature!
@Tac the syntax for the Messenger Doctrine transport is explained in this Symfony Docs pull request pending to be merged:

https://github.com/symfony/symfony-docs/pull/10616/files
Great ! Thank you :)
Nice feature! Thank you!

btw, ^ (the above comment): is it related to Symfony?
Nice to see this feature :)
Login with SymfonyConnect to post a comment