Skip to content

Commit 92d95dd

Browse files
saschanowakbmack
authored andcommitted
[BUGFIX] Allow to configure RateLimiters in message consumer
This fix adds the missing configuration options for the rate limiters. A "rate limiter" manages the frequency at which a particular messages, such as an HTTP request or a login attempt, can occur. Rate limiting serves as a protective mechanism to prevent services from being overwhelmed by excessive usage, whether intentional or accidental, thus ensuring their continued availability. Additionally, it proves beneficial in regulating internal or outbound processes, such as limiting the simultaneous processing of messages. Resolves: #103140 Releases: main, 13.4 Change-Id: I248e97fbd2d969986513cfc4f8b3a8ffaab585d4 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83052 Reviewed-by: Garvin Hicking <[email protected]> Tested-by: Garvin Hicking <[email protected]> Tested-by: core-ci <[email protected]> Tested-by: Benni Mack <[email protected]> Reviewed-by: Benni Mack <[email protected]>
1 parent bb9a138 commit 92d95dd

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

typo3/sysext/core/Classes/Command/ConsumeMessagesCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function __construct(
4646
private readonly MessageBusInterface $messageBus,
4747
private readonly ServiceLocator $receiverLocator,
4848
private readonly StopWorkerOnTimeLimitListener $stopWorkerOnTimeLimitListener,
49+
private readonly ServiceLocator $rateLimiterLocator,
4950
private readonly EventDispatcherInterface $eventDispatcher,
5051
private readonly array $receiverNames = [],
5152
private readonly array $busIds = [],
@@ -130,6 +131,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
130131
}
131132

132133
$receivers[$receiverName] = $this->receiverLocator->get($receiverName);
134+
if ($this->rateLimiterLocator->has($receiverName)) {
135+
$rateLimiters[$receiverName] = $this->rateLimiterLocator->get($receiverName);
136+
}
133137
}
134138

135139
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);

typo3/sysext/core/Configuration/Services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ services:
172172
arguments:
173173
$messageBus: '@messenger.bus.default'
174174
$receiverLocator: !tagged_locator { tag: 'messenger.receiver', index_by: 'identifier' }
175+
$rateLimiterLocator: !tagged_locator { tag: 'messenger.rate_limiter', index_by: 'identifier' }
175176

176177
TYPO3\CMS\Core\Messenger\EventListener\StopWorkerOnTimeLimitListener:
177178
arguments:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)