Skip to content

Commit ec7b390

Browse files
committed
minor #10644 [Messenger] Fix documentation after 4.2 BC Breaks (ogizanagi)
This PR was merged into the master branch. Discussion ---------- [Messenger] Fix documentation after 4.2 BC Breaks For now, just proof-reading the 4.2 documention to fix latest BC breaks in the component. Commits ------- c8c6645 [Messenger] Fix documentation after 4.2 BC Breaks
2 parents 0bb5e2b + c8c6645 commit ec7b390

File tree

2 files changed

+133
-165
lines changed

2 files changed

+133
-165
lines changed

components/messenger.rst

+33-34
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Concepts
3838
something can be a message broker or a third party API for example.
3939

4040
**Receiver**:
41-
Responsible for deserializing and forwarding messages to handler(s). This
42-
can be a message queue puller or an API endpoint for example.
41+
Responsible for retrieving, deserializing and forwarding messages to handler(s).
42+
This can be a message queue puller or an API endpoint for example.
4343

4444
**Handler**:
4545
Responsible for handling messages using the business logic applicable to the messages.
@@ -55,7 +55,7 @@ are configured for you:
5555

5656
#. ``LoggingMiddleware`` (logs the processing of your messages)
5757
#. ``SendMessageMiddleware`` (enables asynchronous processing)
58-
#. ``HandleMessageMiddleware`` (calls the registered handle)
58+
#. ``HandleMessageMiddleware`` (calls the registered handler)
5959

6060
Example::
6161

@@ -99,57 +99,54 @@ Adding Metadata to Messages (Envelopes)
9999
---------------------------------------
100100

101101
If you need to add metadata or some configuration to a message, wrap it with the
102-
:class:`Symfony\\Component\\Messenger\\Envelope` class. For example, to set the
103-
serialization groups used when the message goes through the transport layer, use
104-
the ``SerializerConfiguration`` envelope::
102+
:class:`Symfony\\Component\\Messenger\\Envelope` class and add stamps.
103+
For example, to set the serialization groups used when the message goes
104+
through the transport layer, use the ``SerializerStamp`` stamp::
105105

106106
use Symfony\Component\Messenger\Envelope;
107-
use Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration;
107+
use Symfony\Component\Messenger\Stamp\SerializerStamp;
108108

109109
$bus->dispatch(
110-
(new Envelope($message))->with(new SerializerConfiguration([
110+
(new Envelope($message))->with(new SerializerStamp([
111111
'groups' => ['my_serialization_groups'],
112112
]))
113113
);
114114

115-
At the moment, the Symfony Messenger has the following built-in envelopes:
115+
At the moment, the Symfony Messenger has the following built-in envelope stamps:
116116

117-
#. :class:`Symfony\\Component\\Messenger\\Transport\\Serialization\\SerializerConfiguration`,
117+
#. :class:`Symfony\\Component\\Messenger\\Stamp\\SerializerStamp`,
118118
to configure the serialization groups used by the transport.
119-
#. :class:`Symfony\\Component\\Messenger\\Middleware\\Configuration\\ValidationConfiguration`,
119+
#. :class:`Symfony\\Component\\Messenger\\Stamp\\ValidationStamp`,
120120
to configure the validation groups used when the validation middleware is enabled.
121-
#. :class:`Symfony\\Component\\Messenger\\Asynchronous\\Transport\\ReceivedMessage`,
121+
#. :class:`Symfony\\Component\\Messenger\\Stamp\\ReceivedStamp`,
122122
an internal item that marks the message as received from a transport.
123123

124-
Instead of dealing directly with the messages in the middleware you can receive the
125-
envelope by implementing the :class:`Symfony\\Component\\Messenger\\EnvelopeAwareInterface`
126-
marker, like this::
124+
Instead of dealing directly with the messages in the middleware you receive the envelope.
125+
Hence you can inspect the envelope content and its stamps, or add any::
127126

128-
use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
127+
use App\Message\Stamp\AnotherStamp;
128+
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
129129
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
130-
use Symfony\Component\Messenger\EnvelopeAwareInterface;
130+
use Symfony\Component\Messenger\Middleware\StackInterface;
131131

132-
class MyOwnMiddleware implements MiddlewareInterface, EnvelopeAwareInterface
132+
class MyOwnMiddleware implements MiddlewareInterface
133133
{
134-
public function handle($envelope, callable $next)
134+
public function handle(Envelope $envelope, StackInterface $stack): Envelope
135135
{
136-
// $envelope here is an `Envelope` object, because this middleware
137-
// implements the EnvelopeAwareInterface interface.
138-
139-
if (null !== $envelope->get(ReceivedMessage::class)) {
136+
if (null !== $envelope->get(ReceivedStamp::class)) {
140137
// Message just has been received...
141138

142139
// You could for example add another item.
143-
$envelope = $envelope->with(new AnotherEnvelopeItem(/* ... */));
140+
$envelope = $envelope->with(new AnotherStamp(/* ... */));
144141
}
145142

146-
return $next($envelope);
143+
return $stack->next()->handle($envelope, $stack);
147144
}
148145
}
149146

150147
The above example will forward the message to the next middleware with an additional
151-
envelope item *if* the message has just been received (i.e. has the `ReceivedMessage` item).
152-
You can create your own items by implementing :class:`Symfony\\Component\\Messenger\\EnvelopeAwareInterface`.
148+
stamp *if* the message has just been received (i.e. has the `ReceivedStamp` stamp).
149+
You can create your own items by implementing :class:`Symfony\\Component\\Messenger\\Stamp\\StampInterface`.
153150

154151
Transports
155152
----------
@@ -170,7 +167,7 @@ First, create your sender::
170167
namespace App\MessageSender;
171168

172169
use App\Message\ImportantAction;
173-
use Symfony\Component\Messenger\Transport\SenderInterface;
170+
use Symfony\Component\Messenger\Transport\Sender\SenderInterface;
174171
use Symfony\Component\Messenger\Envelope;
175172

176173
class ImportantActionToEmailSender implements SenderInterface
@@ -184,7 +181,7 @@ First, create your sender::
184181
$this->toEmail = $toEmail;
185182
}
186183

187-
public function send(Envelope $envelope)
184+
public function send(Envelope $envelope): Envelope
188185
{
189186
$message = $envelope->getMessage();
190187

@@ -200,13 +197,15 @@ First, create your sender::
200197
'text/html'
201198
)
202199
);
200+
201+
return $envelope;
203202
}
204203
}
205204

206205
Your own Receiver
207206
~~~~~~~~~~~~~~~~~
208207

209-
A receiver is responsible for receiving messages from a source and dispatching
208+
A receiver is responsible for getting messages from a source and dispatching
210209
them to the application.
211210

212211
Imagine you already processed some "orders" in your application using a
@@ -222,11 +221,11 @@ First, create your receiver::
222221
namespace App\MessageReceiver;
223222

224223
use App\Message\NewOrder;
225-
use Symfony\Component\Messenger\Transport\ReceiverInterface;
224+
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
226225
use Symfony\Component\Serializer\SerializerInterface;
227226
use Symfony\Component\Messenger\Envelope;
228227

229-
class NewOrdersFromCsvFile implements ReceiverInterface
228+
class NewOrdersFromCsvFileReceiver implements ReceiverInterface
230229
{
231230
private $serializer;
232231
private $filePath;
@@ -258,8 +257,8 @@ Receiver and Sender on the same Bus
258257
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259258

260259
To allow sending and receiving messages on the same bus and prevent an infinite
261-
loop, the message bus will add a :class:`Symfony\\Component\\Messenger\\Asynchronous\\Transport\\ReceivedMessage`
262-
envelope item to the message envelopes and the :class:`Symfony\\Component\\Messenger\\Asynchronous\\Middleware\\SendMessageMiddleware`
260+
loop, the message bus will add a :class:`Symfony\\Component\\Messenger\\Stamp\\ReceivedStamp`
261+
stamp to the message envelopes and the :class:`Symfony\\Component\\Messenger\\Middleware\\SendMessageMiddleware`
263262
middleware will know it should not route these messages again to a transport.
264263

265264
.. _blog posts about command buses: https://matthiasnoback.nl/tags/command%20bus/

0 commit comments

Comments
 (0)