[Messenger] New transport.serializer configuration #49256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
here is a proposal for Messenger, in order to improve processing for messages incoming into the app (ie: messages produced by another app) and messages outgoing from the app (ie: messages produced by our app but intended to be consumed by other apps).
Problem with incoming messages: (see #49094)
If messages are incoming in the app under different formats (json, xml, whatever) there is no easy way to customize per transport in which format the transport will deserialize the message. Same problem occurs for serialization context. Another annoyance is that we need to create a custom serializer class to determine in which class we want to deserialize the message.
This PR proposes a new configuration to handle this:
Problem with outgoing messages: (see #49081)
Messages which are made to be processed by other apps should be sanitized: stamps and header
type
must be removed, otherwise they could create errors in other apps (ie: if the message class does not have the same FQCN in both apps, or if the bus' name in sender app does not exist in receiver app: both of these cases will trigger errors when processing messages in the receiver app).Outgoing messages may also be required to have specific format/context, so we must be able to configure format, context and serializer service used.
IMHO, both of these cases are such common, that they should not require boilerplate in userland.
At the end, the PR also provides the ability to add serialization context/format/service per transport, for all other cases:
Options
incoming_message_serializer
,outgoing_message_serializer
andserializer
are incompatibleAnother solution for the problem would have been to keep only one
serializer
option, along with atype
option (normal|incoming|outgoing|custom
). But the allowed underlying options and behavior really differ from one type to another, that I preferred using 3 different options.