Skip to content

Commit 509e149

Browse files
committed
Add a documentation about middlewares and update based on reviews
1 parent fb88abc commit 509e149

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

components/messenger.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ Concepts
3838
Bus
3939
---
4040

41-
The bus is used to dispatch messages. MessageBus' behaviour is in its ordered
42-
middleware stack. When using the message bus with Symfony's FrameworkBundle, the
43-
following middlewares are configured for you:
41+
The bus is used to dispatch messages. The behaviour of the bus is in its ordered
42+
middleware stack. The component comes with a set of middlewares that you can use.
43+
44+
When using the message bus with Symfony's FrameworkBundle, the following middlewares
45+
are configured for you:
4446

4547
#. :code:`LoggingMiddleware` (logs the processing of your messages)
4648
#. :code:`SendMessageMiddleware` (enables asynchronous processing)
@@ -56,11 +58,15 @@ Example::
5658
$bus = new MessageBus([
5759
new HandleMessageMiddleware(new HandlerLocator([
5860
MyMessage::class => $handler,
59-
]))
61+
])),
6062
]);
6163

6264
$result = $bus->handle(new MyMessage(/* ... */));
6365

66+
.. note:
67+
68+
Every middleware need to implement the :code:`MiddlewareInterface` interface.
69+
6470
Handlers
6571
--------
6672

@@ -87,11 +93,8 @@ Adapters
8793
The communication with queuing system or third parties is delegated to
8894
libraries for now.
8995

90-
Create your adapter
91-
~~~~~~~~~~~~~~~~~~~
92-
9396
Your own sender
94-
---------------
97+
~~~~~~~~~~~~~~~
9598

9699
Using the ``SenderInterface``, you can easily create your own message sender.
97100
Let's say you already have an ``ImportantAction`` message going through the
@@ -134,7 +137,7 @@ First, create your sender::
134137
}
135138

136139
Your own receiver
137-
-----------------
140+
~~~~~~~~~~~~~~~~~
138141

139142
A receiver is responsible for receiving messages from a source and dispatching
140143
them to the application.

messenger.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ the messenger component, the following configuration should have been created:
9393
adapters:
9494
default: "%env(MESSENGER_DSN)%"
9595
96-
.. code-block:: env
96+
.. code-block:: bash
9797
9898
# .env
9999
###> symfony/messenger ###
@@ -169,6 +169,21 @@ like this:
169169
The first argument is the receiver's service name. It might have been created by
170170
your :code:`adapters` configuration or it can be your own receiver.
171171

172+
Registering your middlewares
173+
----------------------------
174+
175+
The message bus is based on middlewares. If you are un-familiar with the concept,
176+
look at the :doc:`Messenger component docs </components/messenger>`.
177+
178+
To register your middleware, use the :code:`messenger.middleware` tag as in the
179+
following example:
180+
181+
.. code-block:: xml
182+
183+
<service id="Your\Own\Middleware">
184+
<tag name="messenger.middleware" />
185+
</service>
186+
172187
Your own Adapters
173188
-----------------
174189

0 commit comments

Comments
 (0)