@@ -135,8 +135,12 @@ Transports
135135By default, messages are processed as soon as they are dispatched. If you prefer
136136to process messages asynchronously, you must configure a transport. These
137137transports communicate with your application via queuing systems or third parties.
138- The built-in AMQP transport allows you to communicate with most of the AMQP
139- brokers such as RabbitMQ.
138+
139+ There are the following built-in transports:
140+
141+ - `AMQP `_
142+ - Doctrine
143+ - `Redis `_
140144
141145.. note ::
142146
@@ -155,7 +159,7 @@ the messenger component, the following configuration should have been created:
155159 framework :
156160 messenger :
157161 transports :
158- amqp : " %env(MESSENGER_TRANSPORT_DSN)%"
162+ your_transport : " %env(MESSENGER_TRANSPORT_DSN)%"
159163
160164 .. code-block :: xml
161165
@@ -171,7 +175,7 @@ the messenger component, the following configuration should have been created:
171175
172176 <framework : config >
173177 <framework : messenger >
174- <framework : transport name =" amqp " dsn =" %env(MESSENGER_TRANSPORT_DSN)%" />
178+ <framework : transport name =" your_transport " dsn =" %env(MESSENGER_TRANSPORT_DSN)%" />
175179 </framework : messenger >
176180 </framework : config >
177181 </container >
@@ -182,33 +186,67 @@ the messenger component, the following configuration should have been created:
182186 $container->loadFromExtension('framework', [
183187 'messenger' => [
184188 'transports' => [
185- 'amqp ' => '%env(MESSENGER_TRANSPORT_DSN)%',
189+ 'your_transport ' => '%env(MESSENGER_TRANSPORT_DSN)%',
186190 ],
187191 ],
188192 ]);
189193
194+ This will also configure the following services for you:
195+
196+ #. A ``messenger.sender.your_transport `` sender to be used when routing messages;
197+ #. A ``messenger.receiver.your_transport `` receiver to be used when consuming messages.
198+
199+ Now define the ``MESSENGER_TRANSPORT_DSN `` in the ``.env `` file.
200+ See examples beneath how to configure the DSN for different transports.
201+
202+ AMQP
203+ ~~~~
204+
190205.. code-block :: bash
191206
192207 # .env
193- # ##> symfony/messenger ###
194208 MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
195- # ##< symfony/messenger ###
196209
197210 This is enough to allow you to route your message to the ``amqp `` transport.
198- This will also configure the following services for you:
199-
200- #. A ``messenger.sender.amqp `` sender to be used when routing messages;
201- #. A ``messenger.receiver.amqp `` receiver to be used when consuming messages.
202211
203212.. note ::
204213
205214 In order to use Symfony's built-in AMQP transport, you will need the AMQP
206- PHP extension and the Serializer Component . Ensure that they are installed with:
215+ PHP extension and the Serializer component . Ensure that they are installed with:
207216
208217 .. code-block :: terminal
209218
210219 $ composer require symfony/amqp-pack
211220
221+ Redis
222+ ~~~~~
223+
224+ .. versionadded :: 4.3
225+
226+ The Redis transport was introduced in Symfony 4.3.
227+
228+ The Redis transport will use `streams `_ to queue messages.
229+
230+ .. code-block :: bash
231+
232+ # .env
233+ MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
234+
235+ This is enough to allow you to route your message to the Redis transport.
236+
237+ If you have multiple systems to receive the same messages you could use different groups
238+ to achieve this:
239+
240+ .. code-block :: bash
241+
242+ # .env
243+ MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages/group1/consumer1
244+
245+ .. note ::
246+
247+ In order to use Symfony's built-in Redis transport, you will need the Redis
248+ PHP extension (^4.2), a running Redis server (^5.0) and the Serializer component.
249+
212250Routing
213251-------
214252
@@ -225,7 +263,7 @@ configuration:
225263 framework :
226264 messenger :
227265 routing :
228- ' My\Message\Message ' : amqp # The name of the defined transport
266+ ' My\Message\Message ' : your_transport # The name of the defined transport
229267
230268 .. code-block :: xml
231269
@@ -242,7 +280,7 @@ configuration:
242280 <framework : config >
243281 <framework : messenger >
244282 <framework : routing message-class =" My\Message\Message" >
245- <framework : sender service =" amqp " />
283+ <framework : sender service =" your_transport " />
246284 </framework : routing >
247285 </framework : messenger >
248286 </framework : config >
@@ -254,7 +292,7 @@ configuration:
254292 $container->loadFromExtension('framework', [
255293 'messenger' => [
256294 'routing' => [
257- 'My\Message\Message' => 'amqp ',
295+ 'My\Message\Message' => 'your_transport ',
258296 ],
259297 ],
260298 ]);
@@ -274,7 +312,7 @@ instead of a class name:
274312 messenger :
275313 routing :
276314 ' My\Message\MessageAboutDoingOperationalWork ' : another_transport
277- ' * ' : amqp
315+ ' * ' : your_transport
278316
279317 .. code-block :: xml
280318
@@ -294,7 +332,7 @@ instead of a class name:
294332 <framework : sender service =" another_transport" />
295333 </framework : routing >
296334 <framework : routing message-class =" *" >
297- <framework : sender service =" amqp " />
335+ <framework : sender service =" your_transport " />
298336 </framework : routing >
299337 </framework : messenger >
300338 </framework : config >
@@ -307,7 +345,7 @@ instead of a class name:
307345 'messenger' => [
308346 'routing' => [
309347 'My\Message\Message' => 'another_transport',
310- '*' => 'amqp ',
348+ '*' => 'your_transport ',
311349 ],
312350 ],
313351 ]);
@@ -322,7 +360,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
322360 framework :
323361 messenger :
324362 routing :
325- ' My\Message\ToBeSentToTwoSenders ' : [amqp , audit]
363+ ' My\Message\ToBeSentToTwoSenders ' : [your_transport , audit]
326364
327365 .. code-block :: xml
328366
@@ -339,7 +377,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
339377 <framework : config >
340378 <framework : messenger >
341379 <framework : routing message-class =" My\Message\ToBeSentToTwoSenders" >
342- <framework : sender service =" amqp " />
380+ <framework : sender service =" your_transport " />
343381 <framework : sender service =" audit" />
344382 </framework : routing >
345383 </framework : messenger >
@@ -352,7 +390,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
352390 $container->loadFromExtension('framework', [
353391 'messenger' => [
354392 'routing' => [
355- 'My\Message\ToBeSentToTwoSenders' => ['amqp ', 'audit'],
393+ 'My\Message\ToBeSentToTwoSenders' => ['your_transport ', 'audit'],
356394 ],
357395 ],
358396 ]);
@@ -369,7 +407,7 @@ while still having them passed to their respective handler:
369407 messenger :
370408 routing :
371409 ' My\Message\ThatIsGoingToBeSentAndHandledLocally ' :
372- senders : [amqp ]
410+ senders : [your_transport ]
373411 send_and_handle : true
374412
375413 .. code-block :: xml
@@ -387,7 +425,7 @@ while still having them passed to their respective handler:
387425 <framework : config >
388426 <framework : messenger >
389427 <framework : routing message-class =" My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle =" true" >
390- <framework : sender service =" amqp " />
428+ <framework : sender service =" your_transport " />
391429 </framework : routing >
392430 </framework : messenger >
393431 </framework : config >
@@ -400,7 +438,7 @@ while still having them passed to their respective handler:
400438 'messenger' => [
401439 'routing' => [
402440 'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [
403- 'senders' => ['amqp '],
441+ 'senders' => ['your_transport '],
404442 'send_and_handle' => true,
405443 ],
406444 ],
@@ -415,7 +453,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this:
415453
416454.. code-block :: terminal
417455
418- $ php bin/console messenger:consume amqp
456+ $ php bin/console messenger:consume your_transport
419457
420458 The first argument is the receiver's service name. It might have been created by
421459your ``transports `` configuration or it can be your own receiver.
@@ -835,3 +873,4 @@ Learn more
835873 /messenger/*
836874
837875.. _`enqueue's transport` : https://github.com/php-enqueue/messenger-adapter
876+ .. _`streams` : https://redis.io/topics/streams-intro
0 commit comments