Skip to content

Commit 3b32336

Browse files
Add documentation for the redis transport
1 parent 0ca6377 commit 3b32336

File tree

1 file changed

+62
-22
lines changed

1 file changed

+62
-22
lines changed

messenger.rst

Lines changed: 62 additions & 22 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,11 +186,22 @@ 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
@@ -195,10 +210,6 @@ the messenger component, the following configuration should have been created:
195210
###< symfony/messenger ###
196211
197212
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.
202213

203214
.. note::
204215

@@ -209,6 +220,35 @@ This will also configure the following services for you:
209220
210221
$ composer require symfony/amqp-pack
211222
223+
Redis
224+
~~~~~
225+
226+
The redis transport will use the redis streams to queue messages.
227+
228+
.. code-block:: bash
229+
230+
# .env
231+
###> symfony/messenger ###
232+
MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
233+
###< symfony/messenger ###
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+
###> symfony/messenger ###
244+
MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages/group1/consumer1
245+
###< symfony/messenger ###
246+
247+
.. note::
248+
249+
In order to use Symfony's built-in Redis transport, you will need the Redis
250+
PHP extension (^4.2), a running Redis Server (^5.0) and the Serializer Component.
251+
212252
Routing
213253
-------
214254

@@ -225,7 +265,7 @@ configuration:
225265
framework:
226266
messenger:
227267
routing:
228-
'My\Message\Message': amqp # The name of the defined transport
268+
'My\Message\Message': your_transport # The name of the defined transport
229269
230270
.. code-block:: xml
231271
@@ -242,7 +282,7 @@ configuration:
242282
<framework:config>
243283
<framework:messenger>
244284
<framework:routing message-class="My\Message\Message">
245-
<framework:sender service="amqp"/>
285+
<framework:sender service="your_transport"/>
246286
</framework:routing>
247287
</framework:messenger>
248288
</framework:config>
@@ -254,7 +294,7 @@ configuration:
254294
$container->loadFromExtension('framework', [
255295
'messenger' => [
256296
'routing' => [
257-
'My\Message\Message' => 'amqp',
297+
'My\Message\Message' => 'your_transport',
258298
],
259299
],
260300
]);
@@ -274,7 +314,7 @@ instead of a class name:
274314
messenger:
275315
routing:
276316
'My\Message\MessageAboutDoingOperationalWork': another_transport
277-
'*': amqp
317+
'*': your_transport
278318
279319
.. code-block:: xml
280320
@@ -294,7 +334,7 @@ instead of a class name:
294334
<framework:sender service="another_transport"/>
295335
</framework:routing>
296336
<framework:routing message-class="*">
297-
<framework:sender service="amqp"/>
337+
<framework:sender service="your_transport"/>
298338
</framework:routing>
299339
</framework:messenger>
300340
</framework:config>
@@ -307,7 +347,7 @@ instead of a class name:
307347
'messenger' => [
308348
'routing' => [
309349
'My\Message\Message' => 'another_transport',
310-
'*' => 'amqp',
350+
'*' => 'your_transport',
311351
],
312352
],
313353
]);
@@ -322,7 +362,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
322362
framework:
323363
messenger:
324364
routing:
325-
'My\Message\ToBeSentToTwoSenders': [amqp, audit]
365+
'My\Message\ToBeSentToTwoSenders': [your_transport, audit]
326366
327367
.. code-block:: xml
328368
@@ -339,7 +379,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
339379
<framework:config>
340380
<framework:messenger>
341381
<framework:routing message-class="My\Message\ToBeSentToTwoSenders">
342-
<framework:sender service="amqp"/>
382+
<framework:sender service="your_transport"/>
343383
<framework:sender service="audit"/>
344384
</framework:routing>
345385
</framework:messenger>
@@ -352,7 +392,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
352392
$container->loadFromExtension('framework', [
353393
'messenger' => [
354394
'routing' => [
355-
'My\Message\ToBeSentToTwoSenders' => ['amqp', 'audit'],
395+
'My\Message\ToBeSentToTwoSenders' => ['your_transport', 'audit'],
356396
],
357397
],
358398
]);
@@ -369,7 +409,7 @@ while still having them passed to their respective handler:
369409
messenger:
370410
routing:
371411
'My\Message\ThatIsGoingToBeSentAndHandledLocally':
372-
senders: [amqp]
412+
senders: [your_transport]
373413
send_and_handle: true
374414
375415
.. code-block:: xml
@@ -387,7 +427,7 @@ while still having them passed to their respective handler:
387427
<framework:config>
388428
<framework:messenger>
389429
<framework:routing message-class="My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle="true">
390-
<framework:sender service="amqp"/>
430+
<framework:sender service="your_transport"/>
391431
</framework:routing>
392432
</framework:messenger>
393433
</framework:config>
@@ -400,7 +440,7 @@ while still having them passed to their respective handler:
400440
'messenger' => [
401441
'routing' => [
402442
'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [
403-
'senders' => ['amqp'],
443+
'senders' => ['your_transport'],
404444
'send_and_handle' => true,
405445
],
406446
],
@@ -415,7 +455,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this:
415455

416456
.. code-block:: terminal
417457
418-
$ php bin/console messenger:consume amqp
458+
$ php bin/console messenger:consume your_transport
419459
420460
The first argument is the receiver's service name. It might have been created by
421461
your ``transports`` configuration or it can be your own receiver.

0 commit comments

Comments
 (0)