File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,55 @@ to multiple transports:
345
345
name as its only argument. For more information about stamps, see
346
346
`Envelopes & Stamps `_.
347
347
348
+ .. _messenger-message-attribute :
349
+
350
+ Configuring Routing Using Attributes
351
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352
+
353
+ You can optionally use the `#[AsMessage] ` attribute to configure message transport::
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 `: configuring multiple
394
+ transports is possible. You may also repeat the attribute if you prefer instead of using
395
+ an array.
396
+
348
397
Doctrine Entities in Messages
349
398
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
350
399
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ HttpKernel
79
79
Messenger
80
80
~~~~~~~~~
81
81
82
+ * :ref: `AsMessage <messenger-message-attribute >`
82
83
* :ref: `AsMessageHandler <messenger-handler >`
83
84
84
85
RemoteEvent
You can’t perform that action at this time.
0 commit comments