@@ -881,6 +881,63 @@ running the ``messenger:consume`` command.
881
881
882
882
.. _messenger-retries-failures :
883
883
884
+ Rate limited transport
885
+ ~~~~~~~~~~~~~~~~~~~~~~
886
+
887
+ Sometimes you might need to rate limit your message worker. You can configure a
888
+ rate limiter on a transport (requires the :doc: `RateLimiter component </rate-limiter >`)
889
+ by setting its ``rate_limiter `` option:
890
+
891
+ .. configuration-block ::
892
+
893
+ .. code-block :: yaml
894
+
895
+ # config/packages/messenger.yaml
896
+ framework :
897
+ messenger :
898
+ transports :
899
+ async :
900
+ rate_limiter : your_rate_limiter_name
901
+
902
+ .. code-block :: xml
903
+
904
+ <!-- config/packages/messenger.xml -->
905
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
906
+ <container xmlns =" http://symfony.com/schema/dic/services"
907
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
908
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
909
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
910
+ https://symfony.com/schema/dic/services/services-1.0.xsd
911
+ http://symfony.com/schema/dic/symfony
912
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
913
+
914
+ <framework : config >
915
+ <framework : messenger >
916
+ <framework : transport name =" async" >
917
+ <option key =" rate_limiter" >your_rate_limiter_name</option >
918
+ </framework : transport >
919
+ </framework : messenger >
920
+ </framework : config >
921
+ </container >
922
+
923
+ .. code-block :: php
924
+
925
+ // config/packages/messenger.php
926
+ use Symfony\Config\FrameworkConfig;
927
+
928
+ return static function (FrameworkConfig $framework) {
929
+ $framework->messenger()
930
+ ->transport('async')
931
+ ->options(['rate_limiter' => 'your_rate_limiter_name'])
932
+ ;
933
+ };
934
+
935
+ .. caution ::
936
+
937
+ When a rate limiter is configured on a transport, it will block the whole
938
+ worker when the limit is hit. You should make sure you configure a dedicated
939
+ worker for a rate limited transport to avoid other transports to be blocked.
940
+
884
941
Retries & Failures
885
942
------------------
886
943
0 commit comments