Important: #103140 - Allow to configure rate limiters in Message consumer (Symfony Messenger)
See forge#103140
Description
This change introduces missing configuration options for Symfony Messenger-based rate limiters.
A rate limiter controls how frequently a specific event (e.g., HTTP request or login attempt) is allowed to occur. It acts as a safeguard to prevent services from being overwhelmed — either accidentally or intentionally — thus helping to maintain their availability.
Rate limiters are also useful for controlling internal or outbound processes, such as limiting the simultaneous processing of messages.
More information about the rate limiter is available in the Symfony Rate Limiter component documentation.
Usage
Configure a rate limiter per queue
Rate limiters can be defined in your service configuration
EXT:
. The name specified
in the settings is resolved to a service tagged with messenger.
and the corresponding identifier.
Example Configuration:
messenger.rate_limiter.demo:
class: 'Symfony\Component\RateLimiter\RateLimiterFactory'
arguments:
$config:
id: 'demo'
policy: 'sliding_window'
limit: '100'
interval: '60 seconds'
$storage: '@Symfony\Component\RateLimiter\Storage\InMemoryStorage'
tags:
- name: 'messenger.rate_limiter'
identifier: 'demo'
messenger.rate_limiter.default:
class: 'Symfony\Component\RateLimiter\RateLimiterFactory'
arguments:
$config:
id: 'default'
policy: 'sliding_window'
limit: '100'
interval: '60 seconds'
$storage: '@Symfony\Component\RateLimiter\Storage\InMemoryStorage'
tags:
- name: 'messenger.rate_limiter'
identifier: 'default'