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

add XML and PHP config examples#13277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 1 commit intosymfony:4.4fromxabbuh:issue-13010
Feb 29, 2020
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 175 additions & 7 deletionsmessenger.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -323,7 +323,7 @@ etc) instead of the object::

// src/Message/NewUserWelcomeEmail.php
namespace App\Message;

class NewUserWelcomeEmail
{
private $userId;
Expand DownExpand Up@@ -671,6 +671,54 @@ this is configurable for each transport:
# implements Symfony\Component\Messenger\Retry\RetryStrategyInterface
# service: null

.. code-block:: xml

<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:messenger>
<framework:transport name="async_priority_high" dsn="%env(MESSENGER_TRANSPORT_DSN)%?queue_name=high_priority">
<framework:retry-strategy max-retries="3" delay="1000" multiplier="2" max-delay="0"/>
</framework:transport>
</framework:messenger>
</framework:config>
</container>

.. code-block:: php

// config/packages/messenger.php
$container->loadFromExtension('framework', [
'messenger' => [
'transports' => [
'async_priority_high' => [
'dsn' => '%env(MESSENGER_TRANSPORT_DSN)%',

// default configuration
'retry_strategy' => [
'max_retries' => 3,
// milliseconds delay
'delay' => 1000,
// causes the delay to be higher before each retry
// e.g. 1 second delay, 2 seconds, 4 seconds
'multiplier' => 2,
'max_delay' => 0,
// override all of this with a service that
// implements Symfony\Component\Messenger\Retry\RetryStrategyInterface
// 'service' => null,
],
],
],
],
]);

Avoiding Retrying
~~~~~~~~~~~~~~~~~

Expand DownExpand Up@@ -702,6 +750,46 @@ be discarded. To avoid this happening, you can instead configure a ``failure_tra

failed: 'doctrine://default?queue_name=failed'

.. code-block:: xml

<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<!-- after retrying, messages will be sent to the "failed" transport -->
<framework:messenger failure-transport="failed">
<!-- ... other transports -->

<framework:transport name="failed" dsn="doctrine://default?queue_name=failed"/>
</framework:messenger>
</framework:config>
</container>

.. code-block:: php

// config/packages/messenger.php
$container->loadFromExtension('framework', [
'messenger' => [
// after retrying, messages will be sent to the "failed" transport
'failure_transport' => 'failed',

'transports' => [
// ... other transports

'failed' => [
'dsn' => 'doctrine://default?queue_name=failed',
],
],
],
]);

In this example, if handling a message fails 3 times (default ``max_retries``),
it will then be sent to the ``failed`` transport. While you *can* use
``messenger:consume failed`` to consume this like a normal transport, you'll
Expand DownExpand Up@@ -947,13 +1035,47 @@ holds them in memory during the request, which can be useful for testing.
For example, if you have an ``async_priority_normal`` transport, you could
override it in the ``test`` environment to use this transport:

..code-block:: yaml
..configuration-block::

# config/packages/test/messenger.yaml
framework:
messenger:
transports:
async_priority_normal: 'in-memory:///'
.. code-block:: yaml

# config/packages/test/messenger.yaml
framework:
messenger:
transports:
async_priority_normal: 'in-memory:///'

.. code-block:: xml

<!-- config/packages/test/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:messenger>
<framework:transport name="async_priority_normal" dsn="in-memory:///"/>
</framework:messenger>
</framework:config>
</container>

.. code-block:: php

// config/packages/test/messenger.php
$container->loadFromExtension('framework', [
'messenger' => [
'transports' => [
'async_priority_normal' => [
'dsn' => 'in-memory:///',
],
],
],
]);

Then, while testing, messages will *not* be delivered to the real transport.
Even better, in a test, you can check that exactly one message was sent
Expand DownExpand Up@@ -1020,6 +1142,52 @@ this globally (or for each transport) to a service that implements
dsn: # ...
serializer: messenger.transport.symfony_serializer

.. code-block:: xml

<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:messenger>
<framework:serializer default-serializer="messenger.transport.symfony_serializer">
<framework:symfony-serializer format="json">
<framework:context/>
</framework:symfony-serializer>
</framework:serializer>

<framework:transport name="async_priority_normal" dsn="..." serializer="messenger.transport.symfony_serializer"/>
</framework:messenger>
</framework:config>
</container>

.. code-block:: php

// config/packages/messenger.php
$container->loadFromExtension('framework', [
'messenger' => [
'serializer' => [
'default_serializer' => 'messenger.transport.symfony_serializer',
'symfony_serializer' => [
'format' => 'json',
'context' => [],
],
],
'transports' => [
'async_priority_normal' => [
'dsn' => // ...
'serializer' => 'messenger.transport.symfony_serializer',
],
],
],
]);

The ``messenger.transport.symfony_serializer`` is a built-in service that uses
the :doc:`Serializer component </serializer>` and can be configured in a few ways.
If you *do* choose to use the Symfony serializer, you can control the context
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp