8000 Merge branch '6.4' into 7.1 · symfony/symfony-docs@382863f · GitHub
[go: up one dir, main page]

Skip to content

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

Appearance settings

Commit 382863f

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: merge configuration blocks for AsMessageHandler attribute
2 parents b68dd90 + a890e57 commit 382863f

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
@@ -2171,51 +2171,36 @@ wherever you need a query bus behavior instead of the ``MessageBusInterface``::
21712171
Customizing Handlers
21722172
--------------------
21732173

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

22102176
Manually Configuring Handlers
22112177
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22122178

22132179
Symfony will normally :ref:`find and register your handler automatically <messenger-handler>`.
22142180
But, you can also configure a handler manually - and pass it some extra config -
2215-
by tagging the handler service with ``messenger.message_handler``
2181+
while using ``#AsMessageHandler`` attribute or tagging the handler service
2182+
with ``messenger.message_handler``.
22162183

22172184
.. configuration-block::
22182185

2186+
.. code-block:: php-attributes
2187+
2188+
// src/MessageHandler/SmsNotificationHandler.php
2189+
namespace App\MessageHandler;
2190+
2191+
use App\Message\OtherSmsNotification;
2192+
use App\Message\SmsNotification;
2193+
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
2194+
2195+
#[AsMessageHandler(fromTransport: 'async', priority: 10)]
2196+
class SmsNotificationHandler
2197+
{
2198+
public function __invoke(SmsNotification $message): void
2199+
{
2200+
// ...
2201+
}
2202+
}
2203+
22192204
.. code-block:: yaml
22202205
22212206
# config/services.yaml

0 commit comments

Comments
 (0)
0