Skip to content

[Messenger] Mention passing arguments along middleware’s id #17853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
and a different instance will be created per bus.

.. configuration-block::

Expand All @@ -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'

Expand All @@ -2379,11 +2384,17 @@ middleware and *only* include your own:
<framework:config>
<framework:messenger>
<!-- default-middleware: disable the default middleware -->
<framework:bus name="messenger.bus.default" default-middleware="false"/>
<framework:bus name="messenger.bus.default" default-middleware="false">

<!-- and/or add your own -->
<framework:middleware id="App\Middleware\MyMiddleware"/>
<framework:middleware id="App\Middleware\AnotherMiddleware"/>
<!-- use and configure parts of the default middleware you want -->
<framework:middleware id="add_bus_name_stamp_middleware">
<framework:argument>messenger.bus.default</framework:argument>
</framework:middleware>

<!-- add your own services that implement Symfony\Component\Messenger\Middleware\MiddlewareInterface -->
<framework:middleware id="App\Middleware\MyMiddleware"/>
<framework:middleware id="App\Middleware\AnotherMiddleware"/>
</framework:bus>
</framework:messenger>
</framework:config>
</container>
Expand All @@ -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
Expand Down