@@ -323,7 +323,7 @@ etc) instead of the object::
323
323
324
324
// src/Message/NewUserWelcomeEmail.php
325
325
namespace App\Message;
326
-
326
+
327
327
class NewUserWelcomeEmail
328
328
{
329
329
private $userId;
@@ -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
@@ -922,13 +1010,47 @@ holds them in memory during the request, which can be useful for testing.
922
1010
For example, if you have an ``async_priority_normal `` transport, you could
923
1011
override it in the ``test `` environment to use this transport:
924
1012
925
- .. code -block :: yaml
1013
+ .. configuration -block ::
926
1014
927
- # config/packages/test/messenger.yaml
928
- framework :
929
- messenger :
930
- transports :
931
- async_priority_normal : ' in-memory:///'
1015
+ .. code-block :: yaml
1016
+
1017
+ # config/packages/test/messenger.yaml
1018
+ framework :
1019
+ messenger :
1020
+ transports :
1021
+ async_priority_normal : ' in-memory:///'
1022
+
1023
+ .. code-block :: xml
1024
+
1025
+ <!-- config/packages/test/messenger.xml -->
1026
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1027
+ <container xmlns =" http://symfony.com/schema/dic/services"
1028
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1029
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1030
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1031
+ https://symfony.com/schema/dic/services/services-1.0.xsd
1032
+ http://symfony.com/schema/dic/symfony
1033
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1034
+
1035
+ <framework : config >
1036
+ <framework : messenger >
1037
+ <framework : transport name =" async_priority_normal" dsn =" in-memory:///" />
1038
+ </framework : messenger >
1039
+ </framework : config >
1040
+ </container >
1041
+
1042
+ .. code-block :: php
1043
+
1044
+ // config/packages/test/messenger.php
1045
+ $container->loadFromExtension('framework', [
1046
+ 'messenger' => [
1047
+ 'transports' => [
1048
+ 'async_priority_normal' => [
1049
+ 'dsn' => 'in-memory:///',
1050
+ ],
1051
+ ],
1052
+ ],
1053
+ ]);
932
1054
933
1055
Then, while testing, messages will *not * be delivered to the real transport.
934
1056
Even better, in a test, you can check that exactly one message was sent
@@ -988,6 +1110,52 @@ this globally (or for each transport) to a service that implements
988
1110
dsn : # ...
989
1111
serializer : messenger.transport.symfony_serializer
990
1112
1113
+ .. code-block :: xml
1114
+
1115
+ <!-- config/packages/messenger.xml -->
1116
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1117
+ <container xmlns =" http://symfony.com/schema/dic/services"
1118
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1119
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1120
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1121
+ https://symfony.com/schema/dic/services/services-1.0.xsd
1122
+ http://symfony.com/schema/dic/symfony
1123
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1124
+
1125
+ <framework : config >
1126
+ <framework : messenger >
1127
+ <framework : serializer default-serializer =" messenger.transport.symfony_serializer" >
1128
+ <framework : symfony-serializer format =" json" >
1129
+ <framework : context />
1130
+ </framework : symfony-serializer >
1131
+ </framework : serializer >
1132
+
1133
+ <framework : transport name =" async_priority_normal" dsn =" ..." serializer =" messenger.transport.symfony_serializer" />
1134
+ </framework : messenger >
1135
+ </framework : config >
1136
+ </container >
1137
+
1138
+ .. code-block :: php
1139
+
1140
+ // config/packages/messenger.php
1141
+ $container->loadFromExtension('framework', [
1142
+ 'messenger' => [
1143
+ 'serializer' => [
1144
+ 'default_serializer' => 'messenger.transport.symfony_serializer',
1145
+ 'symfony_serializer' => [
1146
+ 'format' => 'json',
1147
+ 'context' => [],
1148
+ ],
1149
+ ],
1150
+ 'transports' => [
1151
+ 'async_priority_normal' => [
1152
+ 'dsn' => // ...
1153
+ 'serializer' => 'messenger.transport.symfony_serializer',
1154
+ ],
1155
+ ],
1156
+ ],
1157
+ ]);
1158
+
991
1159
The ``messenger.transport.symfony_serializer `` is a built-in service that uses
992
1160
the :doc: `Serializer component </serializer >` and can be configured in a few ways.
993
1161
If you *do * choose to use the Symfony serializer, you can control the context
0 commit comments