@@ -104,27 +104,45 @@ in an ``Envelope`` and add some ``SerializerConfiguration``::
104
104
]))
105
105
);
106
106
107
- Instead of dealing directly with the message in the handlers or middleware, you
108
- can receive the envelope by implementing the ``EnvelopeAwareInterface `` marker,
109
- like this::
107
+ At the moment, the Symfony Messenger has the following built-in envelopes:
110
108
109
+ 1. :class: `Symfony\\ Component\\ Messenger\\ Transport\\ Serialization\\ SerializerConfiguration `,
110
+ to configure the serialization groups used by the transport.
111
+ 2. :class: `Symfony\\ Component\\ Messenger\\ Middleware\\ Configuration\\ ValidationConfiguration `,
112
+ to configure the validation groups used when the validation middleware is enabled.
113
+ 3. :class: `Symfony\\ Component\\ Messenger\\ Asynchronous\\ Transport\\ ReceivedMessage `,
114
+ an internal item that marks the message as received from a transport.
115
+
116
+ Instead of dealing directly with the messages in the middleware you can receive the
117
+ envelope by implementing the :class: `Symfony\\ Component\\ Messenger\\ EnvelopeAwareInterface `
118
+ marker, like this::
119
+
120
+ use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
111
121
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
112
122
use Symfony\Component\Messenger\EnvelopeAwareInterface;
113
123
114
124
class MyOwnMiddleware implements MiddlewareInterface, EnvelopeAwareInterface
115
125
{
116
126
public function handle($message, callable $next)
117
127
{
118
- // $message here is an `Envelope` object
128
+ // $message here is an `Envelope` object, because this middleware
129
+ // implements the EnvelopeAwareInterface interface. Otherwise,
130
+ // it would be the "original" message.
131
+
132
+ if (null !== $message->get(ReceivedMessage::class)) {
133
+ // Message just has been received...
134
+
135
+ // You could for example add another item.
136
+ $message = $message->with(new AnotherEnvelopeItem(/* ... */));
137
+ }
119
138
120
- return $next(
121
- $message->with(new AnotherEnvelopeItem(/* ... */))
122
- );
139
+ return $next($message);
123
140
}
124
141
}
125
142
126
143
The above example will forward the message to the next middleware with an additional
127
- envelope item. You can create your own items by implementing the ``EnvelopeItemInterface ``
144
+ envelope item if the message has just been received (i.e. has the `ReceivedMessage ` item).
145
+ You can create your own items by implementing the :class: `Symfony\\ Component\\ Messenger\\ EnvelopeAwareInterface `
128
146
interface.
129
147
130
148
Transports
@@ -234,7 +252,6 @@ Receiver and Sender on the same bus
234
252
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235
253
236
254
To allow us to receive and send messages on the same bus and prevent an infinite
237
- loop, the message bus is equipped with the ``WrapIntoReceivedMessage `` middleware.
238
- It will add a ``ReceivedMessage `` configuration to the message envelopes and the
239
- ``SendMessageMiddleware `` middleware will know it should not route these messages
240
- again to a transport.
255
+ loop, the message bus will add a :class: `Symfony\\ Component\\ Messenger\\ Asynchronous\\ Transport\\ ReceivedMessage `
256
+ envelope item to the message envelopes and the :class: `Symfony\\ Component\\ Messenger\\ Asynchronous\\ Middleware\\ SendMessageMiddleware `
257
+ middleware will know it should not route these messages again to a transport.
0 commit comments