@@ -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,11 +186,22 @@ 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
@@ -195,10 +210,6 @@ the messenger component, the following configuration should have been created:
195
210
# ##< symfony/messenger ###
196
211
197
212
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
213
203
214
.. note ::
204
215
@@ -209,6 +220,35 @@ This will also configure the following services for you:
209
220
210
221
$ composer require symfony/amqp-pack
211
222
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
+
212
252
Routing
213
253
-------
214
254
@@ -225,7 +265,7 @@ configuration:
225
265
framework :
226
266
messenger :
227
267
routing :
228
- ' My\Message\Message ' : amqp # The name of the defined transport
268
+ ' My\Message\Message ' : your_transport # The name of the defined transport
229
269
230
270
.. code-block :: xml
231
271
@@ -242,7 +282,7 @@ configuration:
242
282
<framework : config >
243
283
<framework : messenger >
244
284
<framework : routing message-class =" My\Message\Message" >
245
- <framework : sender service =" amqp " />
285
+ <framework : sender service =" your_transport " />
246
286
</framework : routing >
247
287
</framework : messenger >
248
288
</framework : config >
@@ -254,7 +294,7 @@ configuration:
254
294
$container->loadFromExtension('framework', [
255
295
'messenger' => [
256
296
'routing' => [
257
- 'My\Message\Message' => 'amqp ',
297
+ 'My\Message\Message' => 'your_transport ',
258
298
],
259
299
],
260
300
]);
@@ -274,7 +314,7 @@ instead of a class name:
274
314
messenger :
275
315
routing :
276
316
' My\Message\MessageAboutDoingOperationalWork ' : another_transport
277
- ' * ' : amqp
317
+ ' * ' : your_transport
278
318
279
319
.. code-block :: xml
280
320
@@ -294,7 +334,7 @@ instead of a class name:
294
334
<framework : sender service =" another_transport" />
295
335
</framework : routing >
296
336
<framework : routing message-class =" *" >
297
- <framework : sender service =" amqp " />
337
+ <framework : sender service =" your_transport " />
298
338
</framework : routing >
299
339
</framework : messenger >
300
340
</framework : config >
@@ -307,7 +347,7 @@ instead of a class name:
307
347
'messenger' => [
308
348
'routing' => [
309
349
'My\Message\Message' => 'another_transport',
310
- '*' => 'amqp ',
350
+ '*' => 'your_transport ',
311
351
],
312
352
],
313
353
]);
@@ -322,7 +362,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
322
362
framework :
323
363
messenger :
324
364
routing :
325
- ' My\Message\ToBeSentToTwoSenders ' : [amqp , audit]
365
+ ' My\Message\ToBeSentToTwoSenders ' : [your_transport , audit]
326
366
327
367
.. code-block :: xml
328
368
@@ -339,7 +379,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
339
379
<framework : config >
340
380
<framework : messenger >
341
381
<framework : routing message-class =" My\Message\ToBeSentToTwoSenders" >
342
- <framework : sender service =" amqp " />
382
+ <framework : sender service =" your_transport " />
343
383
<framework : sender service =" audit" />
344
384
</framework : routing >
345
385
</framework : messenger >
@@ -352,7 +392,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
352
392
$container->loadFromExtension('framework', [
353
393
'messenger' => [
354
394
'routing' => [
355
- 'My\Message\ToBeSentToTwoSenders' => ['amqp ', 'audit'],
395
+ 'My\Message\ToBeSentToTwoSenders' => ['your_transport ', 'audit'],
356
396
],
357
397
],
358
398
]);
@@ -369,7 +409,7 @@ while still having them passed to their respective handler:
369
409
messenger :
370
410
routing :
371
411
' My\Message\ThatIsGoingToBeSentAndHandledLocally ' :
372
- senders : [amqp ]
412
+ senders : [your_transport ]
373
413
send_and_handle : true
374
414
375
415
.. code-block :: xml
@@ -387,7 +427,7 @@ while still having them passed to their respective handler:
387
427
<framework : config >
388
428
<framework : messenger >
389
429
<framework : routing message-class =" My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle =" true" >
390
- <framework : sender service =" amqp " />
430
+ <framework : sender service =" your_transport " />
391
431
</framework : routing >
392
432
</framework : messenger >
393
433
</framework : config >
@@ -400,7 +440,7 @@ while still having them passed to their respective handler:
400
440
'messenger' => [
401
441
'routing' => [
402
442
'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [
403
- 'senders' => ['amqp '],
443
+ 'senders' => ['your_transport '],
404
444
'send_and_handle' => true,
405
445
],
406
446
],
@@ -415,7 +455,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this:
415
455
416
456
.. code-block :: terminal
417
457
418
- $ php bin/console messenger:consume amqp
458
+ $ php bin/console messenger:consume your_transport
419
459
420
460
The first argument is the receiver's service name. It might have been created by
421
461
your ``transports `` configuration or it can be your own receiver.
0 commit comments