8000 minor #12535 Middleware clarification about being called on "receive"… · symfony/symfony-docs@f31fa44 · GitHub
[go: up one dir, main page]

Skip to content

Commit f31fa44

Browse files
committed
minor #12535 Middleware clarification about being called on "receive" (weaverryan)
This PR was squashed before being merged into the 4.3 branch (closes #12535). Discussion ---------- Middleware clarification about being called on "receive" Hi! A clarification that middleware may be called twice. I think this is the best spot, and isn't too big or too small. Commits ------- b9f315f Middleware clarification about being called on \"receive\"
2 parents ebdb15e + b9f315f commit f31fa44

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

components/messenger.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Concepts
5454
For instance: logging, validating a message, starting a transaction, ...
5555
They are also responsible for calling the next middleware in the chain,
5656
which means they can tweak the envelope, by adding stamps to it or even
57-
replacing it, as well as interrupt the middleware chain.
57+
replacing it, as well as interrupt the middleware chain. Middleware are called
58+
both when a message is originally dispatched and again later when a message
59+
is received from a tansport,
5860

5961
**Envelope**
6062
Messenger specific concept, it gives full flexibility inside the message bus,
@@ -174,6 +176,8 @@ Hence you can inspect the envelope content and its stamps, or add any::
174176

175177
// You could for example add another stamp.
176178
$envelope = $envelope->with(new AnotherStamp(/* ... */));
179+
} else {
180+
// Message was just originally dispatched
177181
}
178182

179183
return $stack->next()->handle($envelope, $stack);

messenger.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,10 @@ for each bus looks like this:
12971297
These middleware names are actually shortcuts names. The real service ids
12981298
are prefixed with ``messenger.middleware.``.
12991299

1300+
The middleware are executed when the message is dispatched but *also* again when
1301+
a message is received via the worker (for messages that were sent to a transport
1302+
to be handled asynchronously). Keep this in mind if you create your own middleware.
1303+
13001304
You can add your own middleware to this list, or completely disable the default
13011305
middleware and *only* include your own:
13021306

0 commit comments

Comments
 (0)
0