Skip to content

Commit

Permalink
[Messenger] document the #[AsMessage] attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pounard committed Jun 28, 2024
1 parent 403f7d4 commit b0dd4fa
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,57 @@ to multiple transports:
name as its only argument. For more information about stamps, see
`Envelopes & Stamps`_.

Configuring Routing Using Attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can optionally use the `#[AsMessage]` attribute to configure message transport:

.. code-block:: php

Check failure on line 353 in messenger.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please do not use ".. code-block:: php", use "::" instead.
// src/Message/SmsNotification.php
namespace App\Message;
use Symfony\Component\Messenger\Attribute\AsMessage;
#[AsMessage(transport: 'async')]
class SmsNotification
{
public function __construct(
private string $content,
) {
}
public function getContent(): string
{
return $this->content;
}
}
.. note::

If you configure routing with both configuration and attributes, the
configuration will take precedence over the attributes and override
them. This allows to override routing on a per-environment basis
for example:

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

Check failure on line 382 in messenger.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line before " .. code-block:: yaml
# config/packages/messenger.yaml
when@dev:
framework:
messenger:
routing:
# override class attribute
'App\Message\SmsNotification': sync

Check failure on line 390 in messenger.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In FrameworkExtension.php line 2252: Invalid Messenger routing configuration: class or interface "App\Message\Sm sNotification" not found.
.. tip::

The `$transport` parameter can be either a `string` or an `array`
or `string`: configuring multiple transports is possible.
You may also repeat the attribute if you prefer instead of using
an array.

Doctrine Entities in Messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit b0dd4fa

Please sign in to comment.