Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Uses Symfony Serializer by default for envelope items #28270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Aug 26, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets #28164
License MIT
Doc PR ø

The original approach was to use serialize/unserialize for envelope items. It turns out it has limitations (see #28247) and reduces the compatibility with 3rd party systems (see #28164). This pull-request changes the existing mechanism by using Symfony Serializer by default.

It keeps the serialize/unserialize mechanism to allow users of the experimental component to keep using it in 4.2 and allow to have a non-disruptive upgrade to 4.2.

@@ -22,12 +22,14 @@ class Serializer implements DecoderInterface, EncoderInterface
private $serializer;
private $format;
private $context;
private $envelopeWithSerialize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeUsingPhpSerialize? (see other comment about "decode")


private function decodeEnvelopeItems($encodedEnvelope)
{
if ($this->envelopeWithSerialize) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this flag be set? isn't isset($encodedEnvelope['headers']['X-Message-Envelope-Items']) enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it would be better 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

@sroze sroze force-pushed the uses-symfony-serializer-for-items-by-default branch from a67fe63 to b6fd7af Compare August 27, 2018 11:36
@ogizanagi
Copy link
Contributor

ogizanagi commented Aug 27, 2018

Rational in original PR was that envelop items are a thing specific to the Symfony Messenger component in order to configure transport & middleware and would not be used by third party systems. So there is no interop required (or that would mean 3rd party systems would have to implement features the same way Symfony Messenger does. Not likely to happen IMHO).

Mentioned use-case in #28270 is about adding headers to the transport layer. Hence this is the transport responsibility. Using directly envelop items for this and relying on the fact those are serialized in X-Message-Envelope-Items looks wrong to me. Instead, I'd say an envelope item should allow configuring headers and our Messenger Serializer use it to add asked headers.

@sroze
Copy link
Contributor Author

sroze commented Aug 27, 2018

So there is no interop required (or that would mean 3rd party systems would have to implement features the same way Symfony Messenger does. Not likely to happen IMHO).

That I don't agree with: even if the envelopes provided by the core are not necessarily aimed to be shared across systems, I don't see why we would enforce their serialization to be obfuscated with PHP's serialize mechanism (in this case, for sure, 3rd parties won't do anything with them). For user-defined envelopes, I'm pretty convinced that this is very valuable to have them serialized in an understandable format (i.e. JSON) so that 3rd parties can account for them.

There is another aspect to it: JSON is much better for backward compatibility. BC is pretty important for anything that is asynchronous (because you can't wait for all the messages to be processed when you deploy the workers) and this is this main reason that I believe we should use Symfony Serializer for this.

Instead, I'd say an envelope item should allow configuring headers and our Messenger Serializer use it to add asked headers.

I definitely do agree with this though: we should add an envelope which could be named MessageHeaderEnvelope that is understood by the Serializer class (in Messenger, obsly) to add custom headers to the messages.

@sroze sroze force-pushed the uses-symfony-serializer-for-items-by-default branch from b6fd7af to 319df2b Compare August 27, 2018 18:26
@fabpot
Copy link
Member

fabpot commented Aug 30, 2018

👍 for using plain JSON via Symfony Serializer (we are moving away from PHP serializer anyway).
👎 for keeping BC with 4.1. The component is marked as experimental for this very reason: allow us to break BC.

@fabpot
Copy link
Member

fabpot commented Sep 4, 2018

@sroze Can you finish this PR?

@sroze sroze force-pushed the uses-symfony-serializer-for-items-by-default branch from 319df2b to 9b575ab Compare September 4, 2018 08:25
@sroze
Copy link
Contributor Author

sroze commented Sep 4, 2018

@fabpot what a nice timing. Just pushed the rebased and updated version without the serialize fallback 😉

@fabpot
Copy link
Member

fabpot commented Sep 4, 2018

Thank you @sroze.

@fabpot fabpot merged commit 9b575ab into symfony:master Sep 4, 2018
fabpot added a commit that referenced this pull request Sep 4, 2018
…elope items (sroze)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Messenger] Uses Symfony Serializer by default for envelope items

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28164
| License       | MIT
| Doc PR        | ø

The original approach was to use `serialize`/`unserialize` for envelope items. It turns out it has limitations (see #28247) and reduces the compatibility with 3rd party systems (see #28164). This pull-request changes the existing mechanism by using Symfony Serializer by default.

It keeps the `serialize`/`unserialize` mechanism to allow users of the experimental component to keep using it in 4.2 and allow to have a non-disruptive upgrade to 4.2.

Commits
-------

9b575ab Uses Symfony Serializer by default for envelope items
@javiereguiluz
Copy link
Member

I've created symfony/symfony-docs#10276 to document this new feature. Please, don't forget to create a doc issue for every new feature.

Also, we have lots of pending issues related to Messenger in the Symfony Docs. We really need your help 🙏 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants