8000 [Messenger] ease usage when dealing with "external" messages · Issue #49094 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Messenger] ease usage when dealing with "external" messages #49094
Closed
@nikophil

Description

@nikophil

Description

Hello,

this issue is a follow up of this PR, I'll try to give a little bit more context on what are the motivation behind this, and I would like to come to a consensus before starting the work 😅

Related to #49081, when it comes to deal with messages coming from another app, messenger has some drawbacks.

The main problem is to define per transport :

  • which format we want to deserialize messages from
  • a (de)serialization context
  • and also which serializer service should be used in \Symfony\Component\Messenger\Transport\Serialization\Serializer, this is quite useful when dealing with big messages that requires specific serialization.

The solution I prefer is the one @ro0NL proposed: add a new prototyped messenger.serializers and deprecate messenger.serializer

Prototype would be:

messenger:
    serializers:
        name:
            default: ~ # exactly one with default:true needed
            serializer: ~ # defaults to `@serializer`
            format: ~ # defaults to json
            context: {} 

Afterwards, we need to link transports to our serializers. There is already a key messenger.transports.serializer which do not represent the same thing (we expect an implementation of \Symfony\Component\Messenger\Transport\Serialization\SerializerInterface here). Maybe we could add a transports key in the messenger.serializers prototype?

Another problem is that we don't have any way to differentiate "messenger serializer" that uses "symfony serializer" and which would need serialization context (ie: \Symfony\Component\Messenger\Transport\Serialization\Serializer) from "messenger serializer" which do not use Symfony's serializer (ie: \Symfony\Component\Messenger\Transport\Serialization\PhpSerializer). That's why I think we need a SymfonySerializerAwareInterface which extends \Symfony\Component\Messenger\Transport\Serialization\SerializerInterface.

At the end, my proposal would be:

messenger:
    serializers:
        name:
            messenger_serializer: ~ # any implementation of `\Symfony\Component\Messenger\Transport\Serialization\SerializerInterface`
            default: ~ # exactly one with "default: true" needed

            # the following would only be allowed if `messenger_serializer` implements a new interface "SymfonySerializerAwareInterface"
            symfony_serializer_service: ~ # defaults to `@serializer`
            format: ~ # defaults to json
            context: {} 

We would then deprecate passing a service to messenger.transports.serializer and now require to pass one of the prototypes above. If nothing is provided under messenger.serializers, we would use \Symfony\Component\Messenger\Transport\Serialization\PhpSerializer

@weaverryan @chalasr @ro0NL I'd love to have your inputs on this <3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0