Skip to content

Commit 0aca6e3

Browse files
committed
Merge remote-tracking branch 'upstream/7.0' into 7.0
* upstream/7.0: - [Messenger] Add messenger rate_limiter docs - Added a paragraph about HttpOptions object
2 parents b847d7b + 57f7840 commit 0aca6e3

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

http_client.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ method to retrieve a new instance of the client with new default options::
144144
'extra' => ['my-key' => 'my-value'],
145145
]);
146146

147+
Alternatively, the :class:`Symfony\\Component\\HttpClient\\HttpOptions` class
148+
brings most of the available options with type-hinted getters and setters::
149+
150+
$this->client = $client->withOptions(
151+
(new HttpOptions())
152+
->setBaseUri('https://...')
153+
->setHeaders(['header-name' => 'header-value'])
154+
->toArray()
155+
);
156+
147157
Some options are described in this guide:
148158

149159
* `Authentication`_

messenger.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,63 @@ running the ``messenger:consume`` command.
881881

882882
.. _messenger-retries-failures:
883883

884+
Rate limited transport
885+
~~~~~~~~~~~~~~~~~~~~~~
886+
887+
Sometimes you might need to rate limit your message worker. You can configure a
888+
rate limiter on a transport (requires the :doc:`RateLimiter component </rate-limiter>`)
889+
by setting its ``rate_limiter`` option:
890+
891+
.. configuration-block::
892+
893+
.. code-block:: yaml
894+
895+
# config/packages/messenger.yaml
896+
framework:
897+
messenger:
898+
transports:
899+
async:
900+
rate_limiter: your_rate_limiter_name
901+
902+
.. code-block:: xml
903+
904+
<!-- config/packages/messenger.xml -->
905+
<?xml version="1.0" encoding="UTF-8" ?>
906+
<container xmlns="http://symfony.com/schema/dic/services"
907+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
908+
xmlns:framework="http://symfony.com/schema/dic/symfony"
909+
xsi:schemaLocation="http://symfony.com/schema/dic/services
910+
https://symfony.com/schema/dic/services/services-1.0.xsd
911+
http://symfony.com/schema/dic/symfony
912+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
913+
914+
<framework:config>
915+
<framework:messenger>
916+
<framework:transport name="async">
917+
<option key="rate_limiter">your_rate_limiter_name</option>
918+
</framework:transport>
919+
</framework:messenger>
920+
</framework:config>
921+
</container>
922+
923+
.. code-block:: php
924+
925+
// config/packages/messenger.php
926+
use Symfony\Config\FrameworkConfig;
927+
928+
return static function (FrameworkConfig $framework) {
929+
$framework->messenger()
930+
->transport('async')
931+
->options(['rate_limiter' => 'your_rate_limiter_name'])
932+
;
933+
};
934+
935+
.. caution::
936+
937+
When a rate limiter is configured on a transport, it will block the whole
938+
worker when the limit is hit. You should make sure you configure a dedicated
939+
worker for a rate limited transport to avoid other transports to be blocked.
940+
884941
Retries & Failures
885942
------------------
886943

0 commit comments

Comments
 (0)