Skip to content

Commit 8dab9e4

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: merge configuration blocks for AsMessageHandler attribute
2 parents 5c72f37 + 382863f commit 8dab9e4

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

messenger.rst

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,51 +2179,36 @@ wherever you need a query bus behavior instead of the ``MessageBusInterface``::
21792179
Customizing Handlers
21802180
--------------------
21812181

2182-
Configuring Handlers Using Attributes
2183-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2184-
2185-
You can configure your handler by passing options to the attribute::
2186-
2187-
// src/MessageHandler/SmsNotificationHandler.php
2188-
namespace App\MessageHandler;
2189-
2190-
use App\Message\OtherSmsNotification;
2191-
use App\Message\SmsNotification;
2192-
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
2193-
2194-
#[AsMessageHandler(fromTransport: 'async', priority: 10)]
2195-
class SmsNotificationHandler
2196-
{
2197-
public function __invoke(SmsNotification $message): void
2198-
{
2199-
// ...
2200-
}
2201-
}
2202-
2203-
Possible options to configure with the attribute are:
2204-
2205-
============================== ====================================================================================================
2206-
Option Description
2207-
============================== ====================================================================================================
2208-
``bus`` Name of the bus from which the handler can receive messages, by default all buses.
2209-
``fromTransport`` Name of the transport from which the handler can receive messages, by default all transports.
2210-
``handles`` Type of messages (FQCN) that can be processed by the handler, only needed if can't be guessed by
2211-
type-hint.
2212-
``method`` Name of the method that will process the message, only if the target is a class.
2213-
``priority`` Priority of the handler when multiple handlers can process the same message.
2214-
============================== ====================================================================================================
2215-
22162182
.. _messenger-handler-config:
22172183

22182184
Manually Configuring Handlers
22192185
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22202186

22212187
Symfony will normally :ref:`find and register your handler automatically <messenger-handler>`.
22222188
But, you can also configure a handler manually - and pass it some extra config -
2223-
by tagging the handler service with ``messenger.message_handler``
2189+
while using ``#AsMessageHandler`` attribute or tagging the handler service
2190+
with ``messenger.message_handler``.
22242191

22252192
.. configuration-block::
22262193

2194+
.. code-block:: php-attributes
2195+
2196+
// src/MessageHandler/SmsNotificationHandler.php
2197+
namespace App\MessageHandler;
2198+
2199+
use App\Message\OtherSmsNotification;
2200+
use App\Message\SmsNotification;
2201+
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
2202+
2203+
#[AsMessageHandler(fromTransport: 'async', priority: 10)]
2204+
class SmsNotificationHandler
2205+
{
2206+
public function __invoke(SmsNotification $message): void
2207+
{
2208+
// ...
2209+
}
2210+
}
2211+
22272212
.. code-block:: yaml
22282213
22292214
# config/services.yaml

0 commit comments

Comments
 (0)