@@ -1994,51 +1994,36 @@ wherever you need a query bus behavior instead of the ``MessageBusInterface``::
1994
1994
Customizing Handlers
1995
1995
--------------------
1996
1996
1997
- Configuring Handlers Using Attributes
1998
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1999
-
2000
- You can configure your handler by passing options to the attribute::
2001
-
2002
- // src/MessageHandler/SmsNotificationHandler.php
2003
- namespace App\MessageHandler;
2004
-
2005
- use App\Message\OtherSmsNotification;
2006
- use App\Message\SmsNotification;
2007
- use Symfony\Component\Messenger\Attribute\AsMessageHandler;
2008
-
2009
- #[AsMessageHandler(fromTransport: 'async', priority: 10)]
2010
- class SmsNotificationHandler
2011
- {
2012
- public function __invoke(SmsNotification $message): void
2013
- {
2014
- // ...
2015
- }
2016
- }
2017
-
2018
- Possible options to configure with the attribute are:
2019
-
2020
- ============================== ====================================================================================================
2021
- Option Description
2022
- ============================== ====================================================================================================
2023
- ``bus `` Name of the bus from which the handler can receive messages, by default all buses.
2024
- ``fromTransport `` Name of the transport from which the handler can receive messages, by default all transports.
2025
- ``handles `` Type of messages (FQCN) that can be processed by the handler, only needed if can't be guessed by
2026
- type-hint.
2027
- ``method `` Name of the method that will process the message, only if the target is a class.
2028
- ``priority `` Priority of the handler when multiple handlers can process the same message.
2029
- ============================== ====================================================================================================
2030
-
2031
1997
.. _messenger-handler-config :
2032
1998
2033
1999
Manually Configuring Handlers
2034
2000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2035
2001
2036
2002
Symfony will normally :ref: `find and register your handler automatically <messenger-handler >`.
2037
2003
But, you can also configure a handler manually - and pass it some extra config -
2038
- by tagging the handler service with ``messenger.message_handler ``
2004
+ while using ``#AsMessageHandler `` attribute or tagging the handler service
2005
+ with ``messenger.message_handler ``.
2039
2006
2040
2007
.. configuration-block ::
2041
2008
2009
+ .. code-block :: php-attributes
2010
+
2011
+ // src/MessageHandler/SmsNotificationHandler.php
2012
+ namespace App\MessageHandler;
2013
+
2014
+ use App\Message\OtherSmsNotification;
2015
+ use App\Message\SmsNotification;
2016
+ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
2017
+
2018
+ #[AsMessageHandler(fromTransport: 'async', priority: 10)]
2019
+ class SmsNotificationHandler
2020
+ {
2021
+ public function __invoke(SmsNotification $message): void
2022
+ {
2023
+ // ...
2024
+ }
2025
+ }
2026
+
2042
2027
.. code-block :: yaml
2043
2028
2044
2029
# config/services.yaml
0 commit comments