File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,56 @@ to multiple transports:
345
345
name as its only argument. For more information about stamps, see
346
346
`Envelopes & Stamps `_.
347
347
348
+ Configuring Routing Using Attributes
349
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
350
+
351
+ You can optionally use the `#[AsMessage] ` attribute to configure message transport:
352
+
353
+ .. code-block :: php
354
+
355
+ // src/Message/SmsNotification.php
356
+ namespace App\Message;
357
+
358
+ use Symfony\Component\Messenger\Attribute\AsMessage;
359
+
360
+ #[AsMessage(transport: 'async')]
361
+ class SmsNotification
362
+ {
363
+ public function __construct(
364
+ private string $content,
365
+ ) {
366
+ }
367
+
368
+ public function getContent(): string
369
+ {
370
+ return $this->content;
371
+ }
372
+ }
373
+
374
+ .. note ::
375
+
376
+ If you configure routing with both configuration and attributes, the
377
+ configuration will take precedence over the attributes and override
378
+ them. This allows to override routing on a per-environment basis
379
+ for example:
380
+
381
+ .. code-block :: yaml
382
+
383
+ # config/packages/messenger.yaml
384
+ when@dev :
385
+ framework :
386
+ messenger :
387
+ routing :
388
+ # override class attribute
389
+ ' App\Message\SmsNotification ' : sync
390
+
391
+ .. tip ::
392
+
393
+ The `$transport ` parameter can be either a `string ` or an `array `
394
+ or `string `: configuring multiple transports is possible.
395
+ You may also repeat the attribute if you prefer instead of using
396
+ an array.
397
+
348
398
Doctrine Entities in Messages
349
399
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
350
400
You can’t perform that action at this time.
0 commit comments