Skip to content

Commit 5bf7179

Browse files
committed
[Messenger] Document serializedTypeName option in AsMessage attribute
1 parent 5066f51 commit 5bf7179

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

messenger.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,39 @@ on a case-by-case basis via the :class:`Symfony\\Component\\Messenger\\Stamp\\Se
20142014
provides that control. See `SymfonyCasts' message serializer tutorial`_ for
20152015
details.
20162016

2017+
Customizing the Serialized Type Name
2018+
....................................
2019+
2020+
.. versionadded:: 8.1
2021+
2022+
The ``serializedTypeName`` option was introduced in Symfony 8.1.
2023+
2024+
By default, when using the Symfony serializer, the ``type`` header of serialized
2025+
messages contains the fully qualified class name (FQCN) of the message class.
2026+
This can cause interoperability issues when communicating with non-Symfony
2027+
applications or when the message class structure differs between applications.
2028+
2029+
To customize the type name, use the ``serializedTypeName`` option of the
2030+
:class:`Symfony\\Component\\Messenger\\Attribute\\AsMessage` attribute::
2031+
2032+
// src/Message/OrderPlaced.php
2033+
namespace App\Message;
2034+
2035+
use Symfony\Component\Messenger\Attribute\AsMessage;
2036+
2037+
#[AsMessage(serializedTypeName: 'order.placed')]
2038+
class OrderPlaced
2039+
{
2040+
public function __construct(
2041+
public string $orderId,
2042+
) {
2043+
}
2044+
}
2045+
2046+
When this message is serialized, the ``type`` header will contain ``order.placed``
2047+
instead of ``App\Message\OrderPlaced``. This makes it easier to consume messages
2048+
from other systems that use different naming conventions.
2049+
20172050
Closing Connections
20182051
~~~~~~~~~~~~~~~~~~~
20192052

0 commit comments

Comments
 (0)