8000 merge configuration blocks for AsMessageHandler attribute · symfony/symfony-docs@b885083 · GitHub
[go: up one dir, main page]

Skip to content

Commit b885083

Browse files
authored
merge configuration blocks for AsMessageHandler attribute
1 parent 8ca8c9b commit b885083

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
@@ -1994,51 +1994,36 @@ wherever you need a query bus behavior instead of the ``MessageBusInterface``::
19941994
Customizing Handlers
19951995
--------------------
19961996

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-
20311997
.. _messenger-handler-config:
20321998

20331999
Manually Configuring Handlers
20342000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20352001

20362002
Symfony will normally :ref:`find and register your handler automatically <messenger-handler>`.
20372003
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``.
20392006

20402007
.. configuration-block::
20412008

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+
20422027
.. code-block:: yaml
20432028
20442029
# config/services.yaml

0 commit comments

Comments
 (0)
0