Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d784895

Browse files
monteirojaviereguiluz
authored andcommitted
[Messenger] Multiple failed transports
1 parent 8190b74 commit d784895

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

messenger.rst

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,110 @@ If the message fails again, it will be re-sent back to the failure transport
865865
due to the normal :ref:`retry rules <messenger-retries-failures>`. Once the max
866866
retry has been hit, the message will be discarded permanently.
867867

868+
Multiple Failed Transports
869+
~~~~~~~~~~~~~~~~~~~~~~~~~~
870+
871+
Sometimes it is not enough to have a single, global ``failed transport`` configured
872+
because some messages are more important than others. In those cases, you can
873+
override the failure transport for only specific transports:
874+
875+
.. configuration-block::
876+
877+
.. code-block:: yaml
878+
879+
# config/packages/messenger.yaml
880+
framework:
881+
messenger:
882+
# after retrying, messages will be sent to the "failed" transport
883+
# by default if no "failed_transport" is configured inside a transport
884+
failure_transport: failed_default
885+
886+
transports:
887+
async_priority_high:
888+
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
889+
failure_transport: failed_high_priority
890+
891+
# since no failed transport is configured, the one used will be
892+
# the global "failure_transport" set
893+
async_priority_low:
894+
dsn: 'doctrine://default?queue_name=async_priority_low'
895+
896+
failed_default: 'doctrine://default?queue_name=failed_default'
897+
failed_high_priority: 'doctrine://default?queue_name=failed_high_priority'
898+
899+
.. code-block:: xml
900+
901+
<!-- config/packages/messenger.xml -->
902+
<?xml version="1.0" encoding="UTF-8" ?>
903+
<container xmlns="http://symfony.com/schema/dic/services"
904+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
905+
xmlns:framework="http://symfony.com/schema/dic/symfony"
906+
xsi:schemaLocation="http://symfony.com/schema/dic/services
907+
https://symfony.com/schema/dic/services/services-1.0.xsd
908+
http://symfony.com/schema/dic/symfony
909+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
910+
911+
<framework:config>
912+
<!-- after retrying, messages will be sent to the "failed" transport
913+
by default if no "failed-transport" is configured inside a transport -->
914+
<framework:messenger failure-transport="failed_default">
915+
<framework:transport name="async_priority_high" dsn="%env(MESSENGER_TRANSPORT_DSN)%" failure-transport="failed_high_priority"/>
916+
<!-- since no "failed_transport" is configured, the one used will be
917+
the global "failed_transport" set -->
918+
<framework:transport name="async_priority_low" dsn="doctrine://default?queue_name=async_priority_low"/>
919+
920+
<framework:transport name="failed_default" dsn="doctrine://default?queue_name=failed_default"/>
921+
<framework:transport name="failed_high_priority" dsn="doctrine://default?queue_name=failed_high_priority"/>
922+
</framework:messenger>
923+
</framework:config>
924+
</container>
925+
926+
.. code-block:: php
927+
928+
// config/packages/messenger.php
929+
$container->loadFromExtension('framework', [
930+
'messenger' => [
931+
// after retrying, messages will be sent to the "failed" transport
932+
// by default if no "failure_transport" is configured inside a transport
933+
'failure_transport' => 'failed_default',
934+
935+
'transports' => [
936+
'async_priority_high' => [
937+
'dsn' => '%env(MESSENGER_TRANSPORT_DSN)%',
938+
'failure_transport' => 'failed_high_priority'
939+
],
940+
// since no failed transport is configured, the one used will be
941+
// the global failure_transport set
942+
'async_priority_low' => [
943+
'dsn' => 'doctrine://default?queue_name=async_priority_low',
944+
],
945+
'failed_default' => [
946+
'dsn' => 'doctrine://default?queue_name=failed_default',
947+
],
948+
'failed_high_priority' => [
949+
'dsn' => 'doctrine://default?queue_name=failed_high_priority',
950+
],
951+
],
952+
],
953+
]);
954+
955+
If there is no ``failure_transport`` defined globally or on the transport level,
956+
the messages will be discarded after the number of retries.
957+
958+
The failed commands have an optional option ``--transport`` to specify
959+
the ``failure_transport`` configured at the transport level.
960+
961+
.. code-block:: terminal
962+
963+
# see all messages in "failure_transport" transport
964+
$ php bin/console messenger:failed:show --transport=failure_transport
965+
966+
# retry specific messages from "failure_transport"
967+
$ php bin/console messenger:failed:retry 20 30 --transport=failure_transport --force
968+
969+
# remove a message without retrying it from "failure_transport"
970+
$ php bin/console messenger:failed:remove 20 --transport=failure_transport
971+
868972
.. _messenger-transports-config:
869973

870974
Transport Configuration

0 commit comments

Comments
 (0)