@@ -84,7 +84,9 @@ message handler. It's a class with an ``__invoke`` method::
84
84
85
85
Message handlers must be registered as services and :doc: `tagged </service_container/tags >`
86
86
with 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 `,
88
90
this is already done for you, thanks to :ref: `autoconfiguration <services-autoconfigure >`.
89
91
90
92
If you're not using service autoconfiguration, then you need to add this config:
@@ -543,11 +545,16 @@ for each bus looks like this:
543
545
#. ``call_message_handler `` middleware. Will call the message handler(s) for the
544
546
given message.
545
547
546
- Adding your own Middleware
547
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
548
+ .. note ::
548
549
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:
551
558
552
559
.. configuration-block ::
553
560
@@ -558,9 +565,7 @@ within the buses to add some extra capabilities like this:
558
565
messenger :
559
566
buses :
560
567
messenger.bus.default :
561
- middleware :
562
- - ' App\Middleware\MyMiddleware'
563
- - ' App\Middleware\AnotherMiddleware'
568
+ default_middleware : false
564
569
565
570
.. code-block :: xml
566
571
@@ -576,10 +581,7 @@ within the buses to add some extra capabilities like this:
576
581
577
582
<framework : config >
578
583
<framework : messenger >
579
- <framework : bus name =" messenger.bus.default" >
580
- <framework : middleware id =" App\Middleware\MyMiddleware
E377
" />
581
- <framework : middleware id =" App\Middleware\AnotherMiddleware" />
582
- </framework : bus >
584
+ <framework : bus name =" messenger.bus.default" default-middleware =" false" />
583
585
</framework : messenger >
584
586
</framework : config >
585
587
</container >
@@ -591,23 +593,17 @@ within the buses to add some extra capabilities like this:
591
593
'messenger' => array(
592
594
'buses' => array(
593
595
'messenger.bus.default' => array(
594
- 'middleware' => array(
595
- 'App\Middleware\MyMiddleware',
596
- 'App\Middleware\AnotherMiddleware',
597
- ),
596
+ 'default_middleware' => false,
598
597
),
599
598
),
600
599
),
601
600
));
602
601
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
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
608
604
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:
611
607
612
608
.. configuration-block ::
613
609
@@ -618,7 +614,9 @@ you can disable them like this:
618
614
messenger :
619
615
buses :
620
616
messenger.bus.default :
621
- default_middleware : false
617
+ middleware :
618
+ - ' App\Middleware\MyMiddleware'
619
+ - ' App\Middleware\AnotherMiddleware'
622
620
623
621
.. code-block :: xml
624
622
@@ -634,7 +632,10 @@ you can disable them like this:
634
632
635
633
<framework : config >
636
634
<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 >
638
639
</framework : messenger >
639
640
</framework : config >
640
641
</container >
@@ -646,12 +647,18 @@ you can disable them like this:
646
647
'messenger' => array(
647
648
'buses' => array(
648
649
'messenger.bus.default' => array(
649
- 'default_middleware' => false,
650
+ 'middleware' => array(
651
+ 'App\Middleware\MyMiddleware',
652
+ 'App\Middleware\AnotherMiddleware',
653
+ ),
650
654
),
651
655
),
652
656
),
653
657
));
654
658
659
+ Note that if the service is abstract, a different instance of the service will
660
+ be created per bus.
661
+
655
662
Using Middleware Factories
656
663
~~~~~~~~~~~~~~~~~~~~~~~~~~
657
664
@@ -674,13 +681,13 @@ factories. Defining such requires a two-step configuration based on Symfony's
674
681
675
682
# Step 2: an abstract definition that will call the factory with default
676
683
# arguments or the ones provided in the middleware config
677
- messenger.middleware.doctrine_transaction_middleware :
684
+ messenger.middleware.doctrine_transaction :
678
685
class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
679
686
factory : ' doctrine.orm.messenger.middleware_factory.transaction:createMiddleware'
680
687
abstract : true
681
688
# the default arguments to use when none provided from config. Example:
682
689
# middleware:
683
- # - doctrine_transaction_middleware : ~
690
+ # - doctrine_transaction : ~
684
691
arguments : ['default']
685
692
686
693
.. code-block :: xml
@@ -703,7 +710,7 @@ factories. Defining such requires a two-step configuration based on Symfony's
703
710
704
711
<!-- Step 2: an abstract definition that will call the factory with default
705
712
arguments or the ones provided in the middleware config -->
706
- <service id =" messenger.middleware.doctrine_transaction_middleware "
713
+ <service id =" messenger.middleware.doctrine_transaction "
707
714
class =" Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware"
708
715
abstract =" true" >
709
716
@@ -729,7 +736,7 @@ factories. Defining such requires a two-step configuration based on Symfony's
729
736
730
737
// Step 2: an abstract definition that will call the factory with default
731
738
// 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)
733
740
->setFactory(array(
734
741
new Reference('doctrine.orm.messenger.middleware_factory.transaction'),
735
742
'createMiddleware'
@@ -742,7 +749,7 @@ which is the argument expected by the
742
749
``Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory::createMiddleware`` method.
743
750
744
751
Then 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:
746
753
747
754
.. configuration-block ::
748
755
@@ -755,9 +762,9 @@ Then you can reference and configure the
755
762
command_bus :
756
763
middleware :
757
764
# Using defaults
758
- - doctrine_transaction_middleware
765
+ - doctrine_transaction
759
766
# Using another entity manager
760
- - doctrine_transaction_middleware : ['custom']
767
+ - doctrine_transaction : ['custom']
761
768
762
769
.. code-block :: xml
763
770
@@ -775,9 +782,9 @@ Then you can reference and configure the
775
782
<framework : messenger >
776
783
<framework : bus name =" command_bus" >
777
784
<!-- Using defaults -->
778
- <framework : middleware id =" doctrine_transaction_middleware " />
785
+ <framework : middleware id =" doctrine_transaction " />
779
786
<!-- Using another entity manager -->
780
- <framework : middleware id =" doctrine_transaction_middleware " >
787
+ <framework : middleware id =" doctrine_transaction " >
781
788
<framework : argument >custom</framework : argument >
782
789
</framework : middleware >
783
790
</framework : bus >
@@ -794,20 +801,15 @@ Then you can reference and configure the
794
801
'command_bus' => array(
795
802
'middleware' => array(
796
803
// Using defaults
797
- 'doctrine_transaction_middleware ',
804
+ 'doctrine_transaction ',
798
805
// Using another entity manager
799
- array('id' => 'doctrine_transaction_middleware ', 'arguments' => array('custom')),
806
+ array('id' => 'doctrine_transaction ', 'arguments' => array('custom')),
800
807
),
801
808
),
802
809
),
803
810
),
804
811
));
805
812
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
-
811
813
.. note ::
812
814
813
815
Middleware factories only allow scalar and array arguments in config (no
@@ -816,9 +818,9 @@ Then you can reference and configure the
816
818
817
819
.. tip ::
818
820
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.
822
824
823
825
Your own Transport
824
826
------------------
0 commit comments