@@ -666,6 +666,54 @@ this is configurable for each transport:
666
666
# implements Symfony\Component\Messenger\Retry\RetryStrategyInterface
667
667
# service: null
668
668
669
+ .. code-block :: xml
670
+
671
+ <!-- config/packages/messenger.xml -->
672
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
673
+ <container xmlns =" http://symfony.com/schema/dic/services"
674
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
675
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
676
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
677
+ https://symfony.com/schema/dic/services/services-1.0.xsd
678
+ http://symfony.com/schema/dic/symfony
679
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
680
+
681
+ <framework : config >
682
+ <framework : messenger >
683
+ <framework : transport name =" async_priority_high" dsn =" %env(MESSENGER_TRANSPORT_DSN)%?queue_name=high_priority" >
684
+ <framework : retry-strategy max-retries =" 3" delay =" 1000" multiplier =" 2" max-delay =" 0" />
685
+ </framework : transport >
686
+ </framework : messenger >
687
+ </framework : config >
688
+ </container >
689
+
690
+ .. code-block :: php
691
+
692
+ // config/packages/messenger.php
693
+ $container->loadFromExtension('framework', [
694
+ 'messenger' => [
695
+ 'transports' => [
696
+ 'async_priority_high' => [
697
+ 'dsn' => '%env(MESSENGER_TRANSPORT_DSN)%',
698
+
699
+ // default configuration
700
+ 'retry_strategy' => [
701
+ 'max_retries' => 3,
702
+ // milliseconds delay
703
+ 'delay' => 1000,
704
+ // causes the delay to be higher before each retry
705
+ // e.g. 1 second delay, 2 seconds, 4 seconds
706
+ 'multiplier' => 2,
707
+ 'max_delay' => 0,
708
+ // override all of this with a service that
709
+ // implements Symfony\Component\Messenger\Retry\RetryStrategyInterface
710
+ // 'service' => null,
711
+ ],
712
+ ],
713
+ ],
714
+ ],
715
+ ]);
716
+
669
717
Avoiding Retrying
670
718
~~~~~~~~~~~~~~~~~
671
719
@@ -697,6 +745,46 @@ be discarded. To avoid this happening, you can instead configure a ``failure_tra
697
745
698
746
failed : ' doctrine://default?queue_name=failed'
699
747
748
+ .. code-block :: xml
749
+
750
+ <!-- config/packages/messenger.xml -->
751
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
752
+ <container xmlns =" http://symfony.com/schema/dic/services"
753
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
754
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
755
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
756
+ https://symfony.com/schema/dic/services/services-1.0.xsd
757
+ http://symfony.com/schema/dic/symfony
758
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
759
+
760
+ <framework : config >
761
+ <!-- after retrying, messages will be sent to the "failed" transport -->
762
+ <framework : messenger failure-transport =" failed" >
763
+ <!-- ... other transports -->
764
+
765
+ <framework : transport name =" failed" dsn =" doctrine://default?queue_name=failed" />
766
+ </framework : messenger >
767
+ </framework : config >
768
+ </container >
769
+
770
+ .. code-block :: php
771
+
772
+ // config/packages/messenger.php
773
+ $container->loadFromExtension('framework', [
774
+ 'messenger' => [
775
+ // after retrying, messages will be sent to the "failed" transport
776
+ 'failure_transport' => 'failed',
777
+
778
+ 'transports' => [
779
+ // ... other transports
780
+
781
+ 'failed' => [
782
+ 'dsn' => 'doctrine://default?queue_name=failed',
783
+ ],
784
+ ],
785
+ ],
786
+ ]);
787
+
700
788
In this example, if handling a message fails 3 times (default ``max_retries ``),
701
789
it will then be sent to the ``failed `` transport. While you *can * use
702
790
``messenger:consume failed `` to consume this like a normal transport, you'll
@@ -963,13 +1051,47 @@ holds them in memory during the request, which can be useful for testing.
963
1051
For example, if you have an ``async_priority_normal `` transport, you could
964
1052
override it in the ``test `` environment to use this transport:
965
1053
966
- .. code -block :: yaml
1054
+ .. configuration -block ::
967
1055
968
- # config/packages/test/messenger.yaml
969
- framework :
970
- messenger :
971
- transports :
972
- async_priority_normal : ' in-memory:///'
1056
+ .. code-block :: yaml
1057
+
1058
+ # config/packages/test/messenger.yaml
1059
+ framework :
1060
+ messenger :
1061
+ transports :
1062
+ async_priority_normal : ' in-memory:///'
1063
+
1064
+ .. code-block :: xml
1065
+
1066
+ <!-- config/packages/test/messenger.xml -->
1067
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1068
+ <container xmlns =" http://symfony.com/schema/dic/services"
1069
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1070
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1071
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1072
+ https://symfony.com/schema/dic/services/services-1.0.xsd
1073
+ http://symfony.com/schema/dic/symfony
1074
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1075
+
1076
+ <framework : config >
1077
+ <framework : messenger >
1078
+ <framework : transport name =" async_priority_normal" dsn =" in-memory:///" />
1079
+ </framework : messenger >
1080
+ </framework : config >
1081
+ </container >
1082
+
1083
+ .. code-block :: php
1084
+
1085
+ // config/packages/test/messenger.php
1086
+ $container->loadFromExtension('framework', [
1087
+ 'messenger' => [
1088
+ 'transports' => [
1089
+ 'async_priority_normal' => [
1090
+ 'dsn' => 'in-memory:///',
1091
+ ],
1092
+ ],
1093
+ ],
1094
+ ]);
973
1095
974
1096
Then, while testing, messages will *not * be delivered to the real transport.
975
1097
Even better, in a test, you can check that exactly one message was sent
@@ -1029,6 +1151,52 @@ this globally (or for each transport) to a service that implements
1029
1151
dsn : # ...
1030
1152
serializer : messenger.transport.symfony_serializer
1031
1153
1154
+ .. code-block :: xml
1155
+
1156
+ <!-- config/packages/messenger.xml -->
1157
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1158
+ <container xmlns =" http://symfony.com/schema/dic/services"
1159
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1160
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1161
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1162
+ https://symfony.com/schema/dic/services/services-1.0.xsd
1163
+ http://symfony.com/schema/dic/symfony
1164
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1165
+
1166
+ <framework : config >
1167
+ <framework : messenger >
1168
+ <framework : serializer default-serializer =" messenger.transport.symfony_serializer" >
1169
+ <framework : symfony-serializer format =" json" >
1170
+ <framework : context />
1171
+ </framework : symfony-serializer >
1172
+ </framework : serializer >
1173
+
1174
+ <framework : transport name =" async_priority_normal" dsn =" ..." serializer =" messenger.transport.symfony_serializer" />
1175
+ </framework : messenger >
1176
+ </framework : config >
1177
+ </container >
1178
+
1179
+ .. code-block :: php
1180
+
1181
+ // config/packages/messenger.php
1182
+ $container->loadFromExtension('framework', [
1183
+ 'messenger' => [
1184
+ 'serializer' => [
1185
+ 'default_serializer' => 'messenger.transport.symfony_serializer',
1186
+ 'symfony_serializer' => [
1187
+ 'format' => 'json',
1188
+ 'context' => [],
1189
+ ],
1190
+ ],
1191
+ 'transports' => [
1192
+ 'async_priority_normal' => [
1193
+ 'dsn' => // ...
1194
+ 'serializer' => 'messenger.transport.symfony_serializer',
1195
+ ],
1196
+ ],
1197
+ ],
1198
+ ]);
1199
+
1032
1200
The ``messenger.transport.symfony_serializer `` is a built-in service that uses
1033
1201
the :doc: `Serializer component </serializer >` and can be configured in a few ways.
1034
1202
If you *do * choose to use the Symfony serializer, you can control the context
0 commit comments