Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9973e87

Browse files
committed
add XML and PHP config examples
1 parentce07ec0 commit9973e87

File tree

1 file changed

+167
-1
lines changed

1 file changed

+167
-1
lines changed

‎messenger.rst‎

Lines changed: 167 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ etc) instead of the object::
323323

324324
// src/Message/NewUserWelcomeEmail.php
325325
namespace App\Message;
326-
326+
327327
class NewUserWelcomeEmail
328328
{
329329
private $userId;
@@ -671,6 +671,54 @@ this is configurable for each transport:
671671
# implements Symfony\Component\Messenger\Retry\RetryStrategyInterface
672672
# service: null
673673
674+
..code-block::xml
675+
676+
<!-- config/packages/messenger.xml-->
677+
<?xml version="1.0" encoding="UTF-8" ?>
678+
<containerxmlns="http://symfony.com/schema/dic/services"
679+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
680+
xmlns:framework="http://symfony.com/schema/dic/symfony"
681+
xsi:schemaLocation="http://symfony.com/schema/dic/services
682+
https://symfony.com/schema/dic/services/services-1.0.xsd
683+
http://symfony.com/schema/dic/symfony
684+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
685+
686+
<framework:config>
687+
<framework:messenger>
688+
<framework:transportname="async_priority_high"dsn="%env(MESSENGER_TRANSPORT_DSN)%?queue_name=high_priority">
689+
<framework:retry-strategymax-retries="3"delay="1000"multiplier="2"max-delay="0"/>
690+
</framework:transport>
691+
</framework:messenger>
692+
</framework:config>
693+
</container>
694+
695+
..code-block::php
696+
697+
// config/packages/messenger.php
698+
$container->loadFromExtension('framework', [
699+
'messenger' => [
700+
'transports' => [
701+
'async_priority_high' => [
702+
'dsn' => '%env(MESSENGER_TRANSPORT_DSN)%',
703+
704+
// default configuration
705+
'retry_strategy' => [
706+
'max_retries' => 3,
707+
// milliseconds delay
708+
'delay' => 1000,
709+
// causes the delay to be higher before each retry
710+
// e.g. 1 second delay, 2 seconds, 4 seconds
711+
'multiplier' => 2,
712+
'max_delay' => 0,
713+
// override all of this with a service that
714+
// implements Symfony\Component\Messenger\Retry\RetryStrategyInterface
715+
// 'service' => null,
716+
],
717+
],
718+
],
719+
],
720+
]);
721+
674722
Avoiding Retrying
675723
~~~~~~~~~~~~~~~~~
676724

@@ -702,6 +750,46 @@ be discarded. To avoid this happening, you can instead configure a ``failure_tra
702750
703751
failed:'doctrine://default?queue_name=failed'
704752
753+
..code-block::xml
754+
755+
<!-- config/packages/messenger.xml-->
756+
<?xml version="1.0" encoding="UTF-8" ?>
757+
<containerxmlns="http://symfony.com/schema/dic/services"
758+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
759+
xmlns:framework="http://symfony.com/schema/dic/symfony"
760+
xsi:schemaLocation="http://symfony.com/schema/dic/services
761+
https://symfony.com/schema/dic/services/services-1.0.xsd
762+
http://symfony.com/schema/dic/symfony
763+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
764+
765+
<framework:config>
766+
<!-- after retrying, messages will be sent to the "failed" transport-->
767+
<framework:messengerfailure-transport="failed">
768+
<!-- ... other transports-->
769+
770+
<framework:transportname="failed"dsn="doctrine://default?queue_name=failed"/>
771+
</framework:messenger>
772+
</framework:config>
773+
</container>
774+
775+
..code-block::php
776+
777+
// config/packages/messenger.php
778+
$container->loadFromExtension('framework', [
779+
'messenger' => [
780+
// after retrying, messages will be sent to the "failed" transport
781+
'failure_transport' => 'failed',
782+
783+
'transports' => [
784+
// ... other transports
785+
786+
'failed' => [
787+
'dsn' => 'doctrine://default?queue_name=failed',
788+
],
789+
],
790+
],
791+
]);
792+
705793
In this example, if handling a message fails 3 times (default ``max_retries``),
706794
it will then be sent to the ``failed`` transport. While you *can* use
707795
``messenger:consume failed`` to consume this like a normal transport, you'll
@@ -955,6 +1043,38 @@ override it in the ``test`` environment to use this transport:
9551043
transports:
9561044
async_priority_normal:'in-memory:///'
9571045
1046+
.. code-block::xml
1047+
1048+
<!-- config/packages/messenger.xml -->
1049+
<?xml version="1.0" encoding="UTF-8" ?>
1050+
<container xmlns="http://symfony.com/schema/dic/services"
1051+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1052+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1053+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1054+
https://symfony.com/schema/dic/services/services-1.0.xsd
1055+
http://symfony.com/schema/dic/symfony
1056+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1057+
1058+
<framework:config>
1059+
<framework:messenger>
1060+
<framework:transport name="async_priority_normal" dsn="in-memory:///"/>
1061+
</framework:messenger>
1062+
</framework:config>
1063+
</container>
1064+
1065+
.. code-block::php
1066+
1067+
// config/packages/messenger.php
1068+
$container->loadFromExtension('framework', [
1069+
'messenger'=> [
1070+
'transports'=> [
1071+
'async_priority_normal'=> [
1072+
'dsn'=> 'in-memory:///',
1073+
],
1074+
],
1075+
],
1076+
]);
1077+
9581078
Then, while testing, messages will *not* be delivered to the real transport.
9591079
Even better, in a test, you can check that exactly one message was sent
9601080
during a request::
@@ -1020,6 +1140,52 @@ this globally (or for each transport) to a service that implements
10201140
dsn:# ...
10211141
serializer:messenger.transport.symfony_serializer
10221142
1143+
..code-block::xml
1144+
1145+
<!-- config/packages/messenger.xml-->
1146+
<?xml version="1.0" encoding="UTF-8" ?>
1147+
<containerxmlns="http://symfony.com/schema/dic/services"
1148+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1149+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1150+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1151+
https://symfony.com/schema/dic/services/services-1.0.xsd
1152+
http://symfony.com/schema/dic/symfony
1153+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1154+
1155+
<framework:config>
1156+
<framework:messenger>
1157+
<framework:serializerdefault-serializer="messenger.transport.symfony_serializer">
1158+
<framework:symfony-serializerformat="json">
1159+
<framework:context />
1160+
</framework:symfony-serializer>
1161+
</framework:serializer>
1162+
1163+
<framework:transportname="async_priority_normal"dsn="..."serializer="messenger.transport.symfony_serializer"/>
1164+
</framework:messenger>
1165+
</framework:config>
1166+
</container>
1167+
1168+
..code-block::php
1169+
1170+
// config/packages/messenger.php
1171+
$container->loadFromExtension('framework', [
1172+
'messenger' => [
1173+
'serializer' => [
1174+
'default_serializer' => 'messenger.transport.symfony_serializer',
1175+
'symfony_serializer' => [
1176+
'format' => 'json',
1177+
'context' => [],
1178+
],
1179+
],
1180+
'transports' => [
1181+
'async_priority_normal' => [
1182+
'dsn' => // ...
1183+
'serializer' => 'messenger.transport.symfony_serializer',
1184+
],
1185+
],
1186+
],
1187+
]);
1188+
10231189
The ``messenger.transport.symfony_serializer`` is a built-in service that uses
10241190
the:doc:`Serializer component</serializer>` and can be configured in a few ways.
10251191
If you *do* choose to use the Symfony serializer, you can control the context

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp