From 8932965e6c973505505c7565a970ecd90e06010a Mon Sep 17 00:00:00 2001 From: Mathieu Date: Thu, 2 Feb 2023 14:40:43 +0100 Subject: [PATCH] [Messenger] Mention passing arguments to abstract definition --- messenger.rst | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/messenger.rst b/messenger.rst index b3840f77344..7866bba72bf 100644 --- a/messenger.rst +++ b/messenger.rst @@ -2343,7 +2343,10 @@ a message is received via the worker (for messages that were sent to a transport to be handled asynchronously). Keep this in mind if you create your own middleware. You can add your own middleware to this list, or completely disable the default -middleware and *only* include your own: +middleware and *only* include your own. + +If a middleware service is abstract, you can configure its constructor's arguments. +A different instance will be created per bus. .. configuration-block:: @@ -2357,9 +2360,11 @@ middleware and *only* include your own: # disable the default middleware default_middleware: false - # and/or add your own middleware: - # service ids that implement Symfony\Component\Messenger\Middleware\MiddlewareInterface + # use and configure parts of the default middleware you want + - 'add_bus_name_stamp_middleware': ['messenger.bus.default'] + + # add your own services that implement Symfony\Component\Messenger\Middleware\MiddlewareInterface - 'App\Middleware\MyMiddleware' - 'App\Middleware\AnotherMiddleware' @@ -2379,11 +2384,17 @@ middleware and *only* include your own: - + - - - + + + messenger.bus.default + + + + + + @@ -2397,16 +2408,16 @@ middleware and *only* include your own: $messenger = $framework->messenger(); $bus = $messenger->bus('messenger.bus.default') - ->defaultMiddleware(false); + ->defaultMiddleware(false); // disable the default middleware + + // use and configure parts of the default middleware you want + $bus->middleware()->id('add_bus_name_stamp_middleware')->arguments(['messenger.bus.default']); + + // add your own services that implement Symfony\Component\Messenger\Middleware\MiddlewareInterface $bus->middleware()->id('App\Middleware\MyMiddleware'); $bus->middleware()->id('App\Middleware\AnotherMiddleware'); }; -.. note:: - - If a middleware service is abstract, a different instance of the service will - be created per bus. - .. _middleware-doctrine: Middleware for Doctrine