|
| 1 | +.. include:: /Includes.rst.txt |
| 2 | + |
| 3 | +.. _important-103140-1708522119: |
| 4 | + |
| 5 | +============================================================================================= |
| 6 | +Important: #103140 - Allow to configure rate limiters in Message consumer (Symfony Messenger) |
| 7 | +============================================================================================= |
| 8 | + |
| 9 | +See :issue:`103140` |
| 10 | + |
| 11 | +Description |
| 12 | +=========== |
| 13 | + |
| 14 | +This change introduces missing configuration options for Symfony Messenger-based |
| 15 | +rate limiters. |
| 16 | + |
| 17 | +A **rate limiter** controls how frequently a specific event (e.g., HTTP request |
| 18 | +or login attempt) is allowed to occur. It acts as a safeguard to prevent services from |
| 19 | +being overwhelmed — either accidentally or intentionally — thus helping |
| 20 | +to maintain their availability. |
| 21 | + |
| 22 | +Rate limiters are also useful for controlling internal or outbound |
| 23 | +processes, such as limiting the simultaneous processing of messages. |
| 24 | + |
| 25 | +More information about the rate limiter is available in the |
| 26 | +`Symfony Rate Limiter component documentation |
| 27 | +<https://symfony.com/doc/current/rate_limiter.html>`__. |
| 28 | + |
| 29 | +Usage |
| 30 | +===== |
| 31 | + |
| 32 | +Configure a rate limiter per queue |
| 33 | +---------------------------------- |
| 34 | + |
| 35 | +Rate limiters can be defined in your service configuration |
| 36 | +:file:`EXT:yourext/Configuration/Services.yaml`. The name specified |
| 37 | +in the settings is resolved to a service tagged with `messenger.rate_limiter` |
| 38 | +and the corresponding identifier. |
| 39 | + |
| 40 | +Example Configuration: |
| 41 | + |
| 42 | +.. code-block:: yaml |
| 43 | + :caption: EXT:yourext/Configuration/Services.yaml |
| 44 | + :emphasize-lines: 10-12,23-25 |
| 45 | +
|
| 46 | + messenger.rate_limiter.demo: |
| 47 | + class: 'Symfony\Component\RateLimiter\RateLimiterFactory' |
| 48 | + arguments: |
| 49 | + $config: |
| 50 | + id: 'demo' |
| 51 | + policy: 'sliding_window' |
| 52 | + limit: '100' |
| 53 | + interval: '60 seconds' |
| 54 | + $storage: '@Symfony\Component\RateLimiter\Storage\InMemoryStorage' |
| 55 | + tags: |
| 56 | + - name: 'messenger.rate_limiter' |
| 57 | + identifier: 'demo' |
| 58 | +
|
| 59 | + messenger.rate_limiter.default: |
| 60 | + class: 'Symfony\Component\RateLimiter\RateLimiterFactory' |
| 61 | + arguments: |
| 62 | + $config: |
| 63 | + id: 'default' |
| 64 | + policy: 'sliding_window' |
| 65 | + limit: '100' |
| 66 | + interval: '60 seconds' |
| 67 | + $storage: '@Symfony\Component\RateLimiter\Storage\InMemoryStorage' |
| 68 | + tags: |
| 69 | + - name: 'messenger.rate_limiter' |
| 70 | + identifier: 'default' |
| 71 | +
|
| 72 | +.. index:: PHP-API, ext:core |
0 commit comments