8000 minor #10476 Add autoconfiguration note for MessageHandlers (Steveb-p) · symfony/symfony-docs@2d35174 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d35174

Browse files
committed
minor #10476 Add autoconfiguration note for MessageHandlers (Steveb-p)
This PR was squashed before being merged into the 4.1 branch (closes #10476). Discussion ---------- Add autoconfiguration note for MessageHandlers This pull request adds a note regarding MessageHandlerInterface causing handlers to automatically register themselves as one. Commits ------- 957b691 Add autoconfiguration note for MessageHandlers
2 parents 4765b7d + 957b691 commit 2d35174

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

messenger.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ message handler. It's a class with an ``__invoke`` method::
4848

4949
// src/MessageHandler/MyMessageHandler.php
5050
namespace App\MessageHandler;
51+
52+
use Symfony\Component\Messenger\Handler;
5153

52-
class MyMessageHandler
54+
class MyMessageHandler implements MessageHandlerInterface
5355
{
5456
public function __invoke(MyMessage $message)
5557
{
5658
// do something with it.
5759
}
5860
}
5961

60-
Once you've created your handler, you need to register it:
62+
Message handlers must be registered as services and :doc:`tagged </service_container/tags>`
63+
with the ``messenger.message_handler`` tag. If you're using the
64+
:ref:`default services.yaml configuration <service-container-services-load-example>`,
65+
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
66+
67+
If you're not using autoconfigure functionality, then you need to register it:
6168

6269
.. configuration-block::
6370

0 commit comments

Comments
 (0)
0