From b9f315ffe7eb9318831e195f129f636eabf733a1 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 22 Oct 2019 10:01:05 -0400 Subject: [PATCH] Middleware clarification about being called on \"receive\" --- components/messenger.rst | 6 +++++- messenger.rst | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/messenger.rst b/components/messenger.rst index c17220d25a3..63761ec3dfc 100644 --- a/components/messenger.rst +++ b/components/messenger.rst @@ -54,7 +54,9 @@ Concepts For instance: logging, validating a message, starting a transaction, ... They are also responsible for calling the next middleware in the chain, which means they can tweak the envelope, by adding stamps to it or even - replacing it, as well as interrupt the middleware chain. + replacing it, as well as interrupt the middleware chain. Middleware are called + both when a message is originally dispatched and again later when a message + is received from a tansport, **Envelope** 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:: // You could for example add another stamp. $envelope = $envelope->with(new AnotherStamp(/* ... */)); + } else { + // Message was just originally dispatched } return $stack->next()->handle($envelope, $stack); diff --git a/messenger.rst b/messenger.rst index 1c4f8c06d91..185da3f5640 100644 --- a/messenger.rst +++ b/messenger.rst @@ -1297,6 +1297,10 @@ for each bus looks like this: These middleware names are actually shortcuts names. The real service ids are prefixed with ``messenger.middleware.``. +The middleware are executed when the message is dispatched but *also* again when +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: