@@ -135,8 +135,12 @@ Transports
135
135
By default, messages are processed as soon as they are dispatched. If you prefer
136
136
to process messages asynchronously, you must configure a transport. These
137
137
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 `_
140
144
141
145
.. note ::
142
146
@@ -155,7 +159,7 @@ the messenger component, the following configuration should have been created:
155
159
framework :
156
160
messenger :
157
161
transports :
158
- amqp : " %env(MESSENGER_TRANSPORT_DSN)%"
162
+ your_transport : " %env(MESSENGER_TRANSPORT_DSN)%"
159
163
160
164
.. code-block :: xml
161
165
@@ -171,7 +175,7 @@ the messenger component, the following configuration should have been created:
171
175
172
176
<framework : config >
173
177
<framework : messenger >
174
- <framework : transport name =" amqp " dsn =" %env(MESSENGER_TRANSPORT_DSN)%" />
178
+ <framework : transport name =" your_transport " dsn =" %env(MESSENGER_TRANSPORT_DSN)%" />
175
179
</framework : messenger >
176
180
</framework : config >
177
181
</container >
@@ -182,33 +186,67 @@ the messenger component, the following configuration should have been created:
182
186
$container->loadFromExtension('framework', [
183
187
'messenger' => [
184
188
'transports' => [
185
- 'amqp ' => '%env(MESSENGER_TRANSPORT_DSN)%',
189
+ 'your_transport ' => '%env(MESSENGER_TRANSPORT_DSN)%',
186
190
],
187
191
],
188
192
]);
189
193
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
+
190
205
.. code-block :: bash
191
206
192
207
# .env
193
- # ##> symfony/messenger ###
194
208
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
195
- # ##< symfony/messenger ###
196
209
197
210
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.
202
211
203
212
.. note ::
204
213
205
214
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:
207
216
208
217
.. code-block :: terminal
209
218
210
219
$ composer require symfony/amqp-pack
211
220
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
+
212
250
Routing
213
251
-------
214
252
@@ -225,7 +263,7 @@ configuration:
225
263
framework :
226
264
messenger :
227
265
routing :
228
- ' My\Message\Message ' : amqp # The name of the defined transport
266
+ ' My\Message\Message ' : your_transport # The name of the defined transport
229
267
230
268
.. code-block :: xml
231
269
@@ -242,7 +280,7 @@ configuration:
242
280
<framework : config >
243
281
<framework : messenger >
244
282
<framework : routing message-class =" My\Message\Message" >
245
- <framework : sender service =" amqp " />
283
+ <framework : sender service =" your_transport " />
246
284
</framework : routing >
247
285
</framework : messenger >
248
286
</framework : config >
@@ -254,7 +292,7 @@ configuration:
254
292
$container->loadFromExtension('framework', [
255
293
'messenger' => [
256
294
'routing' => [
257
- 'My\Message\Message' => 'amqp ',
295
+ 'My\Message\Message' => 'your_transport ',
258
296
],
259
297
],
260
298
]);
@@ -274,7 +312,7 @@ instead of a class name:
274
312
messenger :
275
313
routing :
276
314
' My\Message\MessageAboutDoingOperationalWork ' : another_transport
277
- ' * ' : amqp
315
+ ' * ' : your_transport
278
316
279
317
.. code-block :: xml
280
318
@@ -294,7 +332,7 @@ instead of a class name:
294
332
<framework : sender service =" another_transport" />
295
333
</framework : routing >
296
334
<framework : routing message-class =" *" >
297
- <framework : sender service =" amqp " />
335
+ <framework : sender service =" your_transport " />
298
336
</framework : routing >
299
337
</framework : messenger >
300
338
</framework : config >
@@ -307,7 +345,7 @@ instead of a class name:
307
345
'messenger' => [
308
346
'routing' => [
309
347
'My\Message\Message' => 'another_transport',
310
- '*' => 'amqp ',
348
+ '*' => 'your_transport ',
311
349
],
312
350
],
313
351
]);
@@ -322,7 +360,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
322
360
framework :
323
361
messenger :
324
362
routing :
325
- ' My\Message\ToBeSentToTwoSenders ' : [amqp , audit]
363
+ ' My\Message\ToBeSentToTwoSenders ' : [your_transport , audit]
326
364
327
365
.. code-block :: xml
328
366
@@ -339,7 +377,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
339
377
<framework : config >
340
378
<framework : messenger >
341
379
<framework : routing message-class =" My\Message\ToBeSentToTwoSenders" >
342
- <framework : sender service =" amqp " />
380
+ <framework : sender service =" your_transport " />
343
381
<framework : sender service =" audit" />
344
382
</framework : routing >
345
383
</framework : messenger >
@@ -352,7 +390,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
352
390
$container->loadFromExtension('framework', [
353
391
'messenger' => [
354
392
'routing' => [
355
- 'My\Message\ToBeSentToTwoSenders' => ['amqp ', 'audit'],
393
+ 'My\Message\ToBeSentToTwoSenders' => ['your_transport ', 'audit'],
356
394
],
357
395
],
358
396
]);
@@ -369,7 +407,7 @@ while still having them passed to their respective handler:
369
407
messenger :
370
408
routing :
371
409
' My\Message\ThatIsGoingToBeSentAndHandledLocally ' :
372
- senders : [amqp ]
410
+ senders : [your_transport ]
373
411
send_and_handle : true
374
412
375
413
.. code-block :: xml
@@ -387,7 +425,7 @@ while still having them passed to their respective handler:
387
425
<framework : config >
388
426
<framework : messenger >
389
427
<framework : routing message-class =" My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle =" true" >
390
- <framework : sender service =" amqp " />
428
+ <framework : sender service =" your_transport " />
391
429
</framework : routing >
392
430
</framework : messenger >
393
431
</framework : config >
@@ -400,7 +438,7 @@ while still having them passed to their respective handler:
400
438
'messenger' => [
401
439
'routing' => [
402
440
'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [
403
- 'senders' => ['amqp '],
441
+ 'senders' => ['your_transport '],
404
442
'send_and_handle' => true,
405
443
],
406
444
],
@@ -415,7 +453,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this:
415
453
416
454
.. code-block :: terminal
417
455
418
- $ php bin/console messenger:consume amqp
456
+ $ php bin/console messenger:consume your_transport
419
457
420
458
The first argument is the receiver's service name. It might have been created by
421
459
your ``transports `` configuration or it can be your own receiver.
@@ -835,3 +873,4 @@ Learn more
835
873
/messenger/*
836
874
837
875
.. _`enqueue's transport` : https://github.com/php-enqueue/messenger-adapter
876
+ .. _`streams` : https://redis.io/topics/streams-intro
0 commit comments