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

Skip to content

Commit af4c0f7

Browse files
committed
minor #15177 [Messenger] Multiple failed transports (monteiro)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Messenger] Multiple failed transports <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> ### New Feature: Messenger: Multiple Failure Transports Transports closes #15168 This PR adds the documentation related to PR: symfony/symfony#38468 What it needs to be clear in the documentation: - You can define multiple transports, one per transport (instead of the global one, as it is supported today) - If you don't define a global failure transport and if the transport does not have the `failure_transport` configured the messages will be discarded - If you define both a global and at the transport level, the `failure_transport` configuration, the one taken into account is at the transport level configuration. - The failed commands have an option argument to specify the transport level `--transport`. Without arguments is the global failed transport taken into account. Commits ------- d784895 [Messenger] Multiple failed transports
2 parents 42963b9 + d784895 commit af4c0f7

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
@@ -872,6 +872,110 @@ If the message fails again, it will be re-sent back to the failure transport
872872
due to the normal :ref:`retry rules <messenger-retries-failures>`. Once the max
873873
retry has been hit, the message will be discarded permanently.
874874

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

877981
Transport Configuration

0 commit comments

Comments
 (0)