Skip to content

Commit fa4e20f

Browse files
committed
feature #17203 [Messenger] Add messenger rate_limiter docs (bobvandevijver)
This PR was submitted for the 6.2 branch but it was squashed and merged into the 6.3 branch instead. Discussion ---------- [Messenger] Add messenger rate_limiter docs Documentation for symfony/symfony#41171 Commits ------- ec2c155 [Messenger] Add messenger rate_limiter docs
2 parents 69062c2 + ec2c155 commit fa4e20f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

messenger.rst

+61
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,67 @@ running the ``messenger:consume`` command.
904904

905905
.. _messenger-retries-failures:
906906

907+
Rate limited transport
908+
~~~~~~~~~~~~~~~~~~~~~~
909+
910+
.. versionadded:: 6.2
911+
912+
The ``rate_limiter`` option was introduced in Symfony 6.2.
913+
914+
Sometimes you might need to rate limit your message worker. You can configure a
915+
rate limiter on a transport (requires the :doc:`RateLimiter component </rate-limiter>`)
916+
by setting its ``rate_limiter`` option:
917+
918+
.. configuration-block::
919+
920+
.. code-block:: yaml
921+
922+
# config/packages/messenger.yaml
923+
framework:
924+
messenger:
925+
transports:
926+
async:
927+
rate_limiter: your_rate_limiter_name
928+
929+
.. code-block:: xml
930+
931+
<!-- config/packages/messenger.xml -->
932+
<?xml version="1.0" encoding="UTF-8" ?>
933+
<container xmlns="http://symfony.com/schema/dic/services"
934+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
935+
xmlns:framework="http://symfony.com/schema/dic/symfony"
936+
xsi:schemaLocation="http://symfony.com/schema/dic/services
937+
https://symfony.com/schema/dic/services/services-1.0.xsd
938+
http://symfony.com/schema/dic/symfony
939+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
940+
941+
<framework:config>
942+
<framework:messenger>
943+
<framework:transport name="async">
944+
<option key="rate_limiter">your_rate_limiter_name</option>
945+
</framework:transport>
946+
</framework:messenger>
947+
</framework:config>
948+
</container>
949+
950+
.. code-block:: php
951+
952+
// config/packages/messenger.php
953+
use Symfony\Config\FrameworkConfig;
954+
955+
return static function (FrameworkConfig $framework) {
956+
$framework->messenger()
957+
->transport('async')
958+
->options(['rate_limiter' => 'your_rate_limiter_name'])
959+
;
960+
};
961+
962+
.. caution::
963+
964+
When a rate limiter is configured on a transport, it will block the whole
965+
worker when the limit is hit. You should make sure you configure a dedicated
966+
worker for a rate limited transport to avoid other transports to be blocked.
967+
907968
Retries & Failures
908969
------------------
909970

0 commit comments

Comments
 (0)