@@ -667,7 +667,7 @@ of some or all transports:
667667 $ php bin/console messenger:stats my_transport_name other_transport_name
668668
669669 .. note ::
670-
670+
671671 In order for this command to work, the configured transport's receiver must implement
672672 :class: `Symfony\\ Component\\ Messenger\\ Transport\\ Receiver\\ MessageCountAwareInterface `.
673673
@@ -1061,7 +1061,7 @@ to retry them:
10611061
10621062 # see all messages in the failure transport with a default limit of 50
10631063 $ php bin/console messenger:failed:show
1064-
1064+
10651065 # see the 10 first messages
10661066 $ php bin/console messenger:failed:show --max=10
10671067
@@ -1935,49 +1935,38 @@ Possible options to configure with tags are:
19351935* ``method ``
19361936* ``priority ``
19371937
1938- Handler Subscriber & Options
1939- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1938+ .. _handler-subscriber-options :
1939+
1940+ Handling Multiple Messages
1941+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
19401942
1941- A handler class can handle multiple messages or configure itself by implementing
1942- :class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageSubscriberInterface `::
1943+ A handler class can handle multiple messages. For that add the ``#AsMessageHandler `` attribute to the handling methods::
19431944
19441945 // src/MessageHandler/SmsNotificationHandler.php
19451946 namespace App\MessageHandler;
19461947
19471948 use App\Message\OtherSmsNotification;
19481949 use App\Message\SmsNotification;
1949- use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
19501950
1951- class SmsNotificationHandler implements MessageSubscriberInterface
1951+ class SmsNotificationHandler
19521952 {
1953- public function __invoke(SmsNotification $message)
1953+ #[AsMessageHandler]
1954+ public function handleSmsNotification(SmsNotification $message)
19541955 {
19551956 // ...
19561957 }
19571958
1959+ #[AsMessageHandler]
19581960 public function handleOtherSmsNotification(OtherSmsNotification $message)
19591961 {
19601962 // ...
19611963 }
1962-
1963- public static function getHandledMessages(): iterable
1964- {
1965- // handle this message on __invoke
1966- yield SmsNotification::class;
1967-
1968- // also handle this message on handleOtherSmsNotification
1969- yield OtherSmsNotification::class => [
1970- 'method' => 'handleOtherSmsNotification',
1971- //'priority' => 0,
1972- //'bus' => 'messenger.bus.default',
1973- ];
1974- }
19751964 }
19761965
19771966.. deprecated :: 6.2
19781967
1979- :class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageSubscriberInterface ` was deprecated in Symfony 6.2.
1980- Use : class: ` #[AsMessageHandler] <Symfony \\ Component \\ Messenger \\ Attribute \\ AsMessageHandler> ` attribute instead .
1968+ Implementing the :class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageSubscriberInterface ` is another way to
1969+ handle multiple messages with one handler class. This interface was deprecated in Symfony 6.2 .
19811970
19821971Binding Handlers to Different Transports
19831972~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2002,38 +1991,25 @@ To do this, add the ``from_transport`` option to each handler. For example::
20021991 namespace App\MessageHandler;
20031992
20041993 use App\Message\UploadedImage;
2005- use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
20061994
2007- class ThumbnailUploadedImageHandler implements MessageSubscriberInterface
1995+ #[AsMessageHandler(from_transport: 'image_transport')]
1996+ class ThumbnailUploadedImageHandler
20081997 {
20091998 public function __invoke(UploadedImage $uploadedImage)
20101999 {
20112000 // do some thumbnailing
20122001 }
2013-
2014- public static function getHandledMessages(): iterable
2015- {
2016- yield UploadedImage::class => [
2017- 'from_transport' => 'image_transport',
2018- ];
2019- }
20202002 }
20212003
20222004And similarly::
20232005
20242006 // src/MessageHandler/NotifyAboutNewUploadedImageHandler.php
20252007 // ...
20262008
2027- class NotifyAboutNewUploadedImageHandler implements MessageSubscriberInterface
2009+ #[AsMessageHandler(from_transport: 'async_priority_normal')]
2010+ class NotifyAboutNewUploadedImageHandler
20282011 {
20292012 // ...
2030-
2031- public static function getHandledMessages(): iterable
2032- {
2033- yield UploadedImage::class => [
2034- 'from_transport' => 'async_priority_normal',
2035- ];
2036- }
20372013 }
20382014
20392015Then, make sure to "route" your message to *both * transports:
0 commit comments