[Messenger] Sanitize message when the receiver is another app
Author: nikophilCreated Jan 23, 2023Updated Sep 28, 2026
LabelsHelp wantedMessenger
Description
Hello,
Messenger is a great component, but has some drawbacks when it comes to send messages across different apps which use messenger.
Let's pretend an app A sends message through rabbitMQ, that will be consumed by an app B
Messages needs to be "sanitized" before leaving the app:
- stamps should be removed: if a stamp exists in app
Aand not in appB, whenAsends messages toB, an error could occur. As well as if appAuses a bus which not exist in appB,Bwill try to get a bus which does not exist and an error will be thrown. - header
typecould also be problematic: if PHP message objects in both apps do not have the same FQCN, when appBreceives the message it will try to deserialize it in a class which does not exist.
A solution would be to add a new interface ExternalMessageInterface and take some actions when the interface is encountered in \Symfony\Component\Messenger\Transport\Serialization\Serializer.
I don't think we could fix this with a middleware, because the header type is added at serialization time.
I'd like to have some feedback on this before fixing it.
Thanks :)
Source: symfony/symfony