Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
49 changes: 49 additions & 0 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,55 @@ to multiple transports:
name as its only argument. For more information about stamps, see
`Envelopes & Stamps`_.

.. _messenger-message-attribute:

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

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

// 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

# config/packages/messenger.yaml
when@dev:
framework:
messenger:
routing:
# override class attribute
'App\Message\SmsNotification': sync

.. tip::

The `$transport` parameter can be either a `string` or an `array`: 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
1 change: 1 addition & 0 deletions reference/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ HttpKernel
Messenger
~~~~~~~~~

* :ref:`AsMessage <messenger-message-attribute>`
* :ref:`AsMessageHandler <messenger-handler>`

RemoteEvent
Expand Down