@@ -84,7 +84,9 @@ message handler. It's a class with an ``__invoke`` method::
8484
8585Message handlers must be registered as services and :doc: `tagged </service_container/tags >`
8686with the ``messenger.message_handler `` tag. If you're using the
87- :ref: `default services.yaml configuration <service-container-services-load-example >`,
87+ :ref: `default services.yaml configuration <service-container-services-load-example >` and implement
88+ :class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageHandlerInterface `
89+ or :class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageSubscriberInterface `,
8890this is already done for you, thanks to :ref: `autoconfiguration <services-autoconfigure >`.
8991
9092If you're not using service autoconfiguration, then you need to add this config:
@@ -543,11 +545,16 @@ for each bus looks like this:
543545#. ``call_message_handler `` middleware. Will call the message handler(s) for the
544546 given message.
545547
546- Adding your own Middleware
547- ~~~~~~~~~~~~~~~~~~~~~~~~~~
548+ .. note ::
548549
549- As described in the component documentation, you can add your own middleware
550- within the buses to add some extra capabilities like this:
550+ These middleware names are actually shortcuts working by convention.
551+ The real service ids are prefixed with the ``messenger.middleware. `` namespace.
552+
553+ Disabling default Middleware
554+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
555+
556+ If you don't want the default collection of middleware to be present on your bus,
557+ you can disable them like this:
551558
552559.. configuration-block ::
553560
@@ -558,9 +565,7 @@ within the buses to add some extra capabilities like this:
558565 messenger :
559566 buses :
560567 messenger.bus.default :
561- middleware :
562- - ' App\Middleware\MyMiddleware'
563- - ' App\Middleware\AnotherMiddleware'
568+ default_middleware : false
564569
565570 .. code-block :: xml
566571
@@ -576,10 +581,7 @@ within the buses to add some extra capabilities like this:
576581
577582 <framework : config >
578583 <framework : messenger >
579- <framework : bus name =" messenger.bus.default" >
580- <framework : middleware id =" App\Middleware\MyMiddleware" />
581- <framework : middleware id =" App\Middleware\AnotherMiddleware" />
582- </framework : bus >
584+ <framework : bus name =" messenger.bus.default" default-middleware =" false" />
583585 </framework : messenger >
584586 </framework : config >
585587 </container >
@@ -591,23 +593,17 @@ within the buses to add some extra capabilities like this:
591593 'messenger' => array(
592594 'buses' => array(
593595 'messenger.bus.default' => array(
594- 'middleware' => array(
595- 'App\Middleware\MyMiddleware',
596- 'App\Middleware\AnotherMiddleware',
597- ),
596+ 'default_middleware' => false,
598597 ),
599598 ),
600599 ),
601600 ));
602601
603- Note that if the service is abstract, a different instance of service will be
604- created per bus.
605-
606- Disabling default Middleware
607- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
602+ Adding your own Middleware
603+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
608604
609- If you don't want the default collection of middleware to be present on your bus,
610- you can disable them like this:
605+ As described in the component documentation, you can add your own middleware
606+ within the buses to add some extra capabilities like this:
611607
612608.. configuration-block ::
613609
@@ -618,7 +614,9 @@ you can disable them like this:
618614 messenger :
619615 buses :
620616 messenger.bus.default :
621- default_middleware : false
617+ middleware :
618+ - ' App\Middleware\MyMiddleware'
619+ - ' App\Middleware\AnotherMiddleware'
622620
623621 .. code-block :: xml
624622
@@ -634,7 +632,10 @@ you can disable them like this:
634632
635633 <framework : config >
636634 <framework : messenger >
637- <framework : bus name =" messenger.bus.default" default-middleware =" false" />
635+ <framework : bus name =" messenger.bus.default" >
636+ <framework : middleware id =" App\Middleware\MyMiddleware" />
637+ <framework : middleware id =" App\Middleware\AnotherMiddleware" />
638+ </framework : bus >
638639 </framework : messenger >
639640 </framework : config >
640641 </container >
@@ -646,12 +647,18 @@ you can disable them like this:
646647 'messenger' => array(
647648 'buses' => array(
648649 'messenger.bus.default' => array(
649- 'default_middleware' => false,
650+ 'middleware' => array(
651+ 'App\Middleware\MyMiddleware',
652+ 'App\Middleware\AnotherMiddleware',
653+ ),
650654 ),
651655 ),
652656 ),
653657 ));
654658
659+ Note that if the service is abstract, a different instance of the service will
660+ be created per bus.
661+
655662Using Middleware Factories
656663~~~~~~~~~~~~~~~~~~~~~~~~~~
657664
@@ -674,13 +681,13 @@ factories. Defining such requires a two-step configuration based on Symfony's
674681
675682 # Step 2: an abstract definition that will call the factory with default
676683 # arguments or the ones provided in the middleware config
677- messenger.middleware.doctrine_transaction_middleware :
684+ messenger.middleware.doctrine_transaction :
678685 class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
679686 factory : ' doctrine.orm.messenger.middleware_factory.transaction:createMiddleware'
680687 abstract : true
681688 # the default arguments to use when none provided from config. Example:
682689 # middleware:
683- # - doctrine_transaction_middleware : ~
690+ # - doctrine_transaction : ~
684691 arguments : ['default']
685692
686693 .. code-block :: xml
@@ -703,7 +710,7 @@ factories. Defining such requires a two-step configuration based on Symfony's
703710
704711 <!-- Step 2: an abstract definition that will call the factory with default
705712 arguments or the ones provided in the middleware config -->
706- <service id =" messenger.middleware.doctrine_transaction_middleware "
713+ <service id =" messenger.middleware.doctrine_transaction "
707714 class =" Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware"
708715 abstract =" true" >
709716
@@ -729,7 +736,7 @@ factories. Defining such requires a two-step configuration based on Symfony's
729736
730737 // Step 2: an abstract definition that will call the factory with default
731738 // arguments or the ones provided in the middleware config
732- $container->register('messenger.middleware.doctrine_transaction_middleware ', DoctrineTransactionMiddleware::class)
739+ $container->register('messenger.middleware.doctrine_transaction ', DoctrineTransactionMiddleware::class)
733740 ->setFactory(array(
734741 new Reference('doctrine.orm.messenger.middleware_factory.transaction'),
735742 'createMiddleware'
@@ -742,7 +749,7 @@ which is the argument expected by the
742749``Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory::createMiddleware `` method.
743750
744751Then you can reference and configure the
745- ``messenger.middleware.doctrine_transaction_middleware `` service as a middleware:
752+ ``messenger.middleware.doctrine_transaction `` service as a middleware:
746753
747754.. configuration-block ::
748755
@@ -755,9 +762,9 @@ Then you can reference and configure the
755762 command_bus :
756763 middleware :
757764 # Using defaults
758- - doctrine_transaction_middleware
765+ - doctrine_transaction
759766 # Using another entity manager
760- - doctrine_transaction_middleware : ['custom']
767+ - doctrine_transaction : ['custom']
761768
762769 .. code-block :: xml
763770
@@ -775,9 +782,9 @@ Then you can reference and configure the
775782 <framework : messenger >
776783 <framework : bus name =" command_bus" >
777784 <!-- Using defaults -->
778- <framework : middleware id =" doctrine_transaction_middleware " />
785+ <framework : middleware id =" doctrine_transaction " />
779786 <!-- Using another entity manager -->
780- <framework : middleware id =" doctrine_transaction_middleware " >
787+ <framework : middleware id =" doctrine_transaction " >
781788 <framework : argument >custom</framework : argument >
782789 </framework : middleware >
783790 </framework : bus >
@@ -794,20 +801,15 @@ Then you can reference and configure the
794801 'command_bus' => array(
795802 'middleware' => array(
796803 // Using defaults
797- 'doctrine_transaction_middleware ',
804+ 'doctrine_transaction ',
798805 // Using another entity manager
799- array('id' => 'doctrine_transaction_middleware ', 'arguments' => array('custom')),
806+ array('id' => 'doctrine_transaction ', 'arguments' => array('custom')),
800807 ),
801808 ),
802809 ),
803810 ),
804811 ));
805812
806- .. note ::
807-
808- The ``doctrine_transaction_middleware `` shortcut is a convention. The real
809- service id is prefixed with the ``messenger.middleware. `` namespace.
810-
811813 .. note ::
812814
813815 Middleware factories only allow scalar and array arguments in config (no
@@ -816,9 +818,9 @@ Then you can reference and configure the
816818
817819.. tip ::
818820
819- The ``doctrine_transaction_middleware `` is a built-in middleware wired
820- automatically when the DoctrineBundle and the Messenger component are
821- installed and enabled.
821+ The ``messenger.middleware.doctrine_transaction `` middleware is a built-in
822+ middleware wired automatically when the DoctrineBundle and the Messenger
823+ component are installed and enabled.
822824
823825Your own Transport
824826------------------
0 commit comments