Skip to content

[Messenger] Add messenger rate_limiter docs #17203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,67 @@ running the ``messenger:consume`` command.

.. _messenger-retries-failures:

Rate limited transport
~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 6.2

The ``rate_limiter`` option was introduced in Symfony 6.2.

Sometimes you might need to rate limit your message worker. You can configure a
rate limiter on a transport (requires the :doc:`RateLimiter component </rate-limiter>`)
by setting its ``rate_limiter`` option:

.. configuration-block::

.. code-block:: yaml

# config/packages/messenger.yaml
framework:
messenger:
transports:
async:
rate_limiter: your_rate_limiter_name

.. code-block:: xml

<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:messenger>
<framework:transport name="async">
<option key="rate_limiter">your_rate_limiter_name</option>
</framework:transport>
</framework:messenger>
</framework:config>
</container>

.. code-block:: php

// config/packages/messenger.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->messenger()
->transport('async')
->options(['rate_limiter' => 'your_rate_limiter_name'])
;
};

.. caution::

When a rate limiter is configured on a transport, it will block the whole
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about such wordings?

As a rate limiter on a transport will block its worker from consuming when the limit is hit,
you may run a dedicated worker handling such transport to avoid others being blocked.

(Perhaps the english is not perfect) but commenting for the idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both are good, it is just a personal preference thing. I don't mind changing it, I also don't mind keeping it as is.

worker when the limit is hit. You should make sure you configure a dedicated
worker for a rate limited transport to avoid other transports to be blocked.

Retries & Failures
------------------

Expand Down