@@ -667,7 +667,7 @@ of some or all transports:
667
667
$ php bin/console messenger:stats my_transport_name other_transport_name
668
668
669
669
.. note ::
670
-
670
+
671
671
In order for this command to work, the configured transport's receiver must implement
672
672
:class: `Symfony\\ Component\\ Messenger\\ Transport\\ Receiver\\ MessageCountAwareInterface `.
673
673
@@ -1061,7 +1061,7 @@ to retry them:
1061
1061
1062
1062
# see all messages in the failure transport with a default limit of 50
1063
1063
$ php bin/console messenger:failed:show
1064
-
1064
+
1065
1065
# see the 10 first messages
1066
1066
$ php bin/console messenger:failed:show --max=10
1067
1067
@@ -1935,49 +1935,38 @@ Possible options to configure with tags are:
1935
1935
* ``method ``
1936
1936
* ``priority ``
1937
1937
1938
- Handler Subscriber & Options
1939
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1938
+ .. _handler-subscriber-options :
1939
+
1940
+ Handling Multiple Messages
1941
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
1940
1942
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::
1943
1944
1944
1945
// src/MessageHandler/SmsNotificationHandler.php
1945
1946
namespace App\MessageHandler;
1946
1947
1947
1948
use App\Message\OtherSmsNotification;
1948
1949
use App\Message\SmsNotification;
1949
- use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
1950
1950
1951
- class SmsNotificationHandler implements MessageSubscriberInterface
1951
+ class SmsNotificationHandler
1952
1952
{
1953
- public function __invoke(SmsNotification $message)
1953
+ #[AsMessageHandler]
1954
+ public function handleSmsNotification(SmsNotification $message)
1954
1955
{
1955
1956
// ...
1956
1957
}
1957
1958
1959
+ #[AsMessageHandler]
1958
1960
public function handleOtherSmsNotification(OtherSmsNotification $message)
1959
1961
{
1960
1962
// ...
1961
1963
}
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
- }
1975
1964
}
1976
1965
1977
1966
.. deprecated :: 6.2
1978
1967
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 .
1981
1970
1982
1971
Binding Handlers to Different Transports
1983
1972
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2002,38 +1991,25 @@ To do this, add the ``from_transport`` option to each handler. For example::
2002
1991
namespace App\MessageHandler;
2003
1992
2004
1993
use App\Message\UploadedImage;
2005
- use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
2006
1994
2007
- class ThumbnailUploadedImageHandler implements MessageSubscriberInterface
1995
+ #[AsMessageHandler(from_transport: 'image_transport')]
1996
+ class ThumbnailUploadedImageHandler
2008
1997
{
2009
1998
public function __invoke(UploadedImage $uploadedImage)
2010
1999
{
2011
2000
// do some thumbnailing
2012
2001
}
2013
-
2014
- public static function getHandledMessages(): iterable
2015
- {
2016
- yield UploadedImage::class => [
2017
- 'from_transport' => 'image_transport',
2018
- ];
2019
- }
2020
2002
}
2021
2003
2022
2004
And similarly::
2023
2005
2024
2006
// src/MessageHandler/NotifyAboutNewUploadedImageHandler.php
2025
2007
// ...
2026
2008
2027
- class NotifyAboutNewUploadedImageHandler implements MessageSubscriberInterface
2009
+ #[AsMessageHandler(from_transport: 'async_priority_normal')]
2010
+ class NotifyAboutNewUploadedImageHandler
2028
2011
{
2029
2012
// ...
2030
-
2031
- public static function getHandledMessages(): iterable
2032
- {
2033
- yield UploadedImage::class => [
2034
- 'from_transport' => 'async_priority_normal',
2035
- ];
2036
- }
2037
2013
}
2038
2014
2039
2015
Then, make sure to "route" your message to *both * transports:
0 commit comments