Skip to content

Commit 1aadc0b

Browse files
committed
feature #11341 Add documentation for the Redis transport (alexander-schranz)
This PR was submitted for the master branch but it was squashed and merged into the 4.3 branch instead (closes #11341). Discussion ---------- Add documentation for the Redis transport This will add documentation how to configure and using the redis transport with the messenger component. symfony/symfony#30917 #EUFOSSA Commits ------- c22fade Add documentation for the Redis transport
2 parents c23a6d6 + c22fade commit 1aadc0b

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

messenger.rst

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ Transports
135135
By default, messages are processed as soon as they are dispatched. If you prefer
136136
to process messages asynchronously, you must configure a transport. These
137137
transports 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,63 @@ 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+
The Redis transport will use `streams`_ to queue messages.
225+
226+
.. code-block:: bash
227+
228+
# .env
229+
MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
230+
231+
This is enough to allow you to route your message to the Redis transport.
232+
233+
If you have multiple systems to receive the same messages you could use different groups
234+
to achieve this:
235+
236+
.. code-block:: bash
237+
238+
# .env
239+
MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages/group1/consumer1
240+
241+
.. note::
242+
243+
In order to use Symfony's built-in Redis transport, you will need the Redis
244+
PHP extension (^4.2), a running Redis server (^5.0) and the Serializer component.
245+
212246
Routing
213247
-------
214248

@@ -225,7 +259,7 @@ configuration:
225259
framework:
226260
messenger:
227261
routing:
228-
'My\Message\Message': amqp # The name of the defined transport
262+
'My\Message\Message': your_transport # The name of the defined transport
229263
230264
.. code-block:: xml
231265
@@ -242,7 +276,7 @@ configuration:
242276
<framework:config>
243277
<framework:messenger>
244278
<framework:routing message-class="My\Message\Message">
245-
<framework:sender service="amqp"/>
279+
<framework:sender service="your_transport"/>
246280
</framework:routing>
247281
</framework:messenger>
248282
</framework:config>
@@ -254,7 +288,7 @@ configuration:
254288
$container->loadFromExtension('framework', [
255289
'messenger' => [
256290
'routing' => [
257-
'My\Message\Message' => 'amqp',
291+
'My\Message\Message' => 'your_transport',
258292
],
259293
],
260294
]);
@@ -274,7 +308,7 @@ instead of a class name:
274308
messenger:
275309
routing:
276310
'My\Message\MessageAboutDoingOperationalWork': another_transport
277-
'*': amqp
311+
'*': your_transport
278312
279313
.. code-block:: xml
280314
@@ -294,7 +328,7 @@ instead of a class name:
294328
<framework:sender service="another_transport"/>
295329
</framework:routing>
296330
<framework:routing message-class="*">
297-
<framework:sender service="amqp"/>
331+
<framework:sender service="your_transport"/>
298332
</framework:routing>
299333
</framework:messenger>
300334
</framework:config>
@@ -307,7 +341,7 @@ instead of a class name:
307341
'messenger' => [
308342
'routing' => [
309343
'My\Message\Message' => 'another_transport',
310-
'*' => 'amqp',
344+
'*' => 'your_transport',
311345
],
312346
],
313347
]);
@@ -322,7 +356,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
322356
framework:
323357
messenger:
324358
routing:
325-
'My\Message\ToBeSentToTwoSenders': [amqp, audit]
359+
'My\Message\ToBeSentToTwoSenders': [your_transport, audit]
326360
327361
.. code-block:: xml
328362
@@ -339,7 +373,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
339373
<framework:config>
340374
<framework:messenger>
341375
<framework:routing message-class="My\Message\ToBeSentToTwoSenders">
342-
<framework:sender service="amqp"/>
376+
<framework:sender service="your_transport"/>
343377
<framework:sender service="audit"/>
344378
</framework:routing>
345379
</framework:messenger>
@@ -352,7 +386,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
352386
$container->loadFromExtension('framework', [
353387
'messenger' => [
354388
'routing' => [
355-
'My\Message\ToBeSentToTwoSenders' => ['amqp', 'audit'],
389+
'My\Message\ToBeSentToTwoSenders' => ['your_transport', 'audit'],
356390
],
357391
],
358392
]);
@@ -369,7 +403,7 @@ while still having them passed to their respective handler:
369403
messenger:
370404
routing:
371405
'My\Message\ThatIsGoingToBeSentAndHandledLocally':
372-
senders: [amqp]
406+
senders: [your_transport]
373407
send_and_handle: true
374408
375409
.. code-block:: xml
@@ -387,7 +421,7 @@ while still having them passed to their respective handler:
387421
<framework:config>
388422
<framework:messenger>
389423
<framework:routing message-class="My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle="true">
390-
<framework:sender service="amqp"/>
424+
<framework:sender service="your_transport"/>
391425
</framework:routing>
392426
</framework:messenger>
393427
</framework:config>
@@ -400,7 +434,7 @@ while still having them passed to their respective handler:
400434
'messenger' => [
401435
'routing' => [
402436
'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [
403-
'senders' => ['amqp'],
437+
'senders' => ['your_transport'],
404438
'send_and_handle' => true,
405439
],
406440
],
@@ -415,7 +449,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this:
415449

416450
.. code-block:: terminal
417451
418-
$ php bin/console messenger:consume amqp
452+
$ php bin/console messenger:consume your_transport
419453
420454
The first argument is the receiver's service name. It might have been created by
421455
your ``transports`` configuration or it can be your own receiver.
@@ -835,3 +869,4 @@ Learn more
835869
/messenger/*
836870

837871
.. _`enqueue's transport`: https://github.com/php-enqueue/messenger-adapter
872+
.. _`streams`: https://redis.io/topics/streams-intro

0 commit comments

Comments
 (0)