Use JMS Serializer with Symfony Messenger.
Add dependency with Composer:
composer require kunicmarko/jms-messenger-adapter
Enable the bundle for all environments:
// bundles.php
return [
//...
KunicMarko\JMSMessengerAdapter\Bridge\Symfony\JMSMessengerAdapterBundle::class => ['all' => true],
];
#config/packages/jms_messenger.yaml
jms_messenger:
format: json # xml, json
serializer_id: messenger.transport.jms_serializer
Serialized id should be configured in the messenger config, in case you did not get the recipe, just add:
#config/packages/jms_messenger.yaml
framework:
messenger:
enabled: true
serializer:
default_serializer: messenger.transport.jms_serializer
This library provides additional stamps that will use JMS Deserialization/Serialization Context for serializing/deserializing messages.
use JMS\Serializer\SerializationContext;
use KunicMarko\JMSMessengerAdapter\Stamp\SerializationContextStamp;
$context = SerializationContext::create();
$context->setGroups(['foo']);
$messageBus->dispatch(new Message(), [new SerializationContextStamp($context)]);