Skip to content

[Messenger] Lazy dependency to the Serializer #26908

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

Closed

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Apr 12, 2018

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

So far, when the serializer was not installed we had the following error message:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 32:

  The service "messenger.adapter.amqp.factory" has a dependency on a non-existent service "messenger.transport.default_encoder".

It will now be:

In Serializer.php line 27:

  A Serializer is required to use this Messenger transport. Try running "composer req serializer".

@sroze
Copy link
Contributor Author

sroze commented Apr 12, 2018

AppVeyor's failure is unrelated.

{
if (null === $serializer) {
throw new \InvalidArgumentException('A Serializer is required to use this Messenger transport. Try running "composer req serializer".');
Copy link
Member

Choose a reason for hiding this comment

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

req -> require (consistency with other spots)

serializer -> symfony/serializer (I think we don't use the aliases in core... just in case there is no Flex)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Changed the wording 👍

{
if (null === $serializer) {
throw new \InvalidArgumentException('A Serializer is required to use this Messenger transport. Try running "composer require symfony/serializer".');
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it's not the responsibility of this class to do that. It should be part of the DI pass, where it was handled before.

Copy link
Contributor

@ogizanagi ogizanagi Apr 12, 2018

Choose a reason for hiding this comment

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

I agree. The benefit is that it'd remain a compile-time check. Here it's only at runtime. Also, it's not necessarily the component that is not installed. It may just not be enabled.

@sroze
Copy link
Contributor Author

sroze commented Apr 12, 2018 via email

@ogizanagi
Copy link
Contributor

Can't it be done from the FrameworkExtension by throwing when trying to use the amqp adapter without the Serializer component installed/enabled?

@sroze
Copy link
Contributor Author

sroze commented Apr 13, 2018

The thing is that you could use the AMQP adapter without Symfony's Serializer component if you use another encoder/decoder. Maybe we can know it when you wire the default encoder/decoder 🤔

@ogizanagi
Copy link
Contributor

@sroze : 🤔AFAIK, there is no configuration for changing the default encoder/decoder. So when using the amqp adapter in messenger config, you'll use the messenger.adapter.amqp.factory which relies on the default encoder/decoder, requiring the serializer. So, if you want to use amqp with a different encoder/decoder, you'll have to create your own service.

Or perhaps you had in mind making the messenger.transport.default_decoder aliases the way for users to change the decoder for instance? I'm not sure this is the best extension point we could made. (BTW, any reason for these aliases to be public?)

@sroze
Copy link
Contributor Author

sroze commented Apr 16, 2018

I think the approach in #26941 is much better. Closing this one.

@sroze sroze closed this Apr 16, 2018
sroze added a commit that referenced this pull request Apr 17, 2018
This PR was squashed before being merged into the 4.1-dev branch (closes #26941).

Discussion
----------

[Messenger] Allow to configure the transport

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

We allow users to configure the encoder/decoder used by the built-in adapter(s). This also adds the support of configuring the default's encoder/decoder format and context.

Commits
-------

1a3f0bb [Messenger] Allow to configure the transport
@sroze sroze deleted the serializer-dependency-more-explicit branch April 17, 2018 17:01
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.

5 participants