@@ -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,63 @@ 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
+ 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
+
212
246
Routing
213
247
-------
214
248
@@ -225,7 +259,7 @@ configuration:
225
259
framework :
226
260
messenger :
227
261
routing :
228
- ' My\Message\Message ' : amqp # The name of the defined transport
262
+ ' My\Message\Message ' : your_transport # The name of the defined transport
229
263
230
264
.. code-block :: xml
231
265
@@ -242,7 +276,7 @@ configuration:
242
276
<framework : config >
243
277
<framework : messenger >
244
278
<framework : routing message-class =" My\Message\Message" >
245
- <framework : sender service =" amqp " />
279
+ <framework : sender service =" your_transport " />
246
280
</framework : routing >
247
281
</framework : messenger >
248
282
</framework : config >
@@ -254,7 +288,7 @@ configuration:
254
288
$container->loadFromExtension('framework', [
255
289
'messenger' => [
256
290
'routing' => [
257
- 'My\Message\Message' => 'amqp ',
291
+ 'My\Message\Message' => 'your_transport ',
258
292
],
259
293
],
260
294
]);
@@ -274,7 +308,7 @@ instead of a class name:
274
308
messenger :
275
309
routing :
276
310
' My\Message\MessageAboutDoingOperationalWork ' : another_transport
277
- ' * ' : amqp
311
+ ' * ' : your_transport
278
312
279
313
.. code-block :: xml
280
314
@@ -294,7 +328,7 @@ instead of a class name:
294
328
<framework : sender service =" another_transport" />
295
329
</framework : routing >
296
330
<framework : routing message-class =" *" >
297
- <framework : sender service =" amqp " />
331
+ <framework : sender service =" your_transport " />
298
332
</framework : routing >
299
333
</framework : messenger >
300
334
</framework : config >
@@ -307,7 +341,7 @@ instead of a class name:
307
341
'messenger' => [
308
342
'routing' => [
309
343
'My\Message\Message' => 'another_transport',
310
- '*' => 'amqp ',
344
+ '*' => 'your_transport ',
311
345
],
312
346
],
313
347
]);
@@ -322,7 +356,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
322
356
framework :
323
357
messenger :
324
358
routing :
325
- ' My\Message\ToBeSentToTwoSenders ' : [amqp , audit]
359
+ ' My\Message\ToBeSentToTwoSenders ' : [your_transport , audit]
326
360
327
361
.. code-block :: xml
328
362
@@ -339,7 +373,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
339
373
<framework : config >
340
374
<framework : messenger >
341
375
<framework : routing message-class =" My\Message\ToBeSentToTwoSenders" >
342
- <framework : sender service =" amqp " />
376
+ <framework : sender service =" your_transport " />
343
377
<framework : sender service =" audit" />
344
378
</framework : routing >
345
379
</framework : messenger >
@@ -352,7 +386,7 @@ A class of messages can also be routed to multiple senders by specifying a list:
352
386
$container->loadFromExtension('framework', [
353
387
'messenger' => [
354
388
'routing' => [
355
- 'My\Message\ToBeSentToTwoSenders' => ['amqp ', 'audit'],
389
+ 'My\Message\ToBeSentToTwoSenders' => ['your_transport ', 'audit'],
356
390
],
357
391
],
358
392
]);
@@ -369,7 +403,7 @@ while still having them passed to their respective handler:
369
403
messenger :
370
404
routing :
371
405
' My\Message\ThatIsGoingToBeSentAndHandledLocally ' :
372
- senders : [amqp ]
406
+ senders : [your_transport ]
373
407
send_and_handle : true
374
408
375
409
.. code-block :: xml
@@ -387,7 +421,7 @@ while still having them passed to their respective handler:
387
421
<framework : config >
388
422
<framework : messenger >
389
423
<framework : routing message-class =" My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle =" true" >
390
- <framework : sender service =" amqp " />
424
+ <framework : sender service =" your_transport " />
391
425
</framework : routing >
392
426
</framework : messenger >
393
427
</framework : config >
@@ -400,7 +434,7 @@ while still having them passed to their respective handler:
400
434
'messenger' => [
401
435
'routing' => [
402
436
'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [
403
- 'senders' => ['amqp '],
437
+ 'senders' => ['your_transport '],
404
438
'send_and_handle' => true,
405
439
],
406
440
],
@@ -415,7 +449,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this:
415
449
416
450
.. code-block :: terminal
417
451
418
- $ php bin/console messenger:consume amqp
452
+ $ php bin/console messenger:consume your_transport
419
453
420
454
The first argument is the receiver's service name. It might have been created by
421
455
your ``transports `` configuration or it can be your own receiver.
@@ -835,3 +869,4 @@ Learn more
835
869
/messenger/*
836
870
837
871
.. _`enqueue's transport` : https://github.com/php-enqueue/messenger-adapter
872
+ .. _`streams` : https://redis.io/topics/streams-intro
0 commit comments