Skip to content

[Messenger] Envelope-aware middleware is never called with a message #27841

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
merged 1 commit into from
Jul 19, 2018
Merged

[Messenger] Envelope-aware middleware is never called with a message #27841

merged 1 commit into from
Jul 19, 2018

Conversation

Cydonia7
Copy link
Contributor

@Cydonia7 Cydonia7 commented Jul 4, 2018

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

Messenger components middlewares implementing Symfony\Component\Messenger\EnvelopeAwareInterface receive in their handle method an instance of Symfony\Component\Messenger\Envelope, not a message.

To better reflect the expected usage, I've updated the unit tests for the message middleware and fixed the code accordingly.

Copy link
Contributor

@sroze sroze left a comment

Choose a reason for hiding this comment

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

Can you rebase on 4.1 and change your PR's base as well?

@@ -36,12 +35,11 @@ public function __construct(SenderLocatorInterface $senderLocator, array $messag
/**
* {@inheritdoc}
*/
public function handle($message, callable $next)
public function handle($envelope, callable $next)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a @param Envelope $envelope above the {@inheritdoc}? I think that this would be better to explicit it's an Envelope.

@Cydonia7 Cydonia7 changed the base branch from master to 4.1 July 4, 2018 12:20
@Cydonia7
Copy link
Contributor Author

Cydonia7 commented Jul 4, 2018

@sroze Comments addressed. I think failures on Appveyor are not related to this PR.

@@ -34,14 +34,15 @@ public function __construct(SenderLocatorInterface $senderLocator, array $messag
}

/**
* @param Envelope $envelope
Copy link
Member

Choose a reason for hiding this comment

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

Since the component is experimental, we can turn this to a real type hint on master at least?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a PR for this (#27322) but I don't think that it's a good idea. At all.

{
$envelope = Envelope::wrap($message);
Copy link
Member

Choose a reason for hiding this comment

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

Could this introduce any BC break?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nop, because EnvelopeAwareInterface, the contract is that it gets an Envelope.

@ogizanagi
Copy link
Contributor

Just to be sure: this is not fixing a bug at all, just removing support of a message in EnvelopeAwareInterface middlewares, right?

Our bus implementation ensures it always receives the Envelope, it's true, but nothing in the design really allows a stronger enforcement here. See symfony/symfony-docs#9757 (comment) discussion and #27322 already mentioned above.
(Note I'm not against this PR, but still proves to me #27322 would be a better design).

Also, the ValidationMiddleware could benefit from similar changes.

@sroze
Copy link
Contributor

sroze commented Jul 8, 2018

Just to be sure: this is not fixing a bug at all, just removing support of a message in EnvelopeAwareInterface middlewares, right?

You are right actually. Maybe we should keep it that way to ensure the middlewares could be used with another bus implementation that does not support the EnvelopeAwareInterface. My 👍 is for this change, so we clarify that this handling of EnvelopeAwareInterface is part of the MessageBusInterface (we could add a comment to it).

@Cydonia7 As per @ogizanagi's comment, can you update the ValidationMiddleware file as well?

@ogizanagi ogizanagi removed the Bug label Jul 8, 2018
@ogizanagi
Copy link
Contributor

ogizanagi commented Jul 8, 2018

So, this cannot be merged in 4.1 as not acceptable in a patch release to me. PR should target and be rebased on master and removal of the support of messages not wrapped in an Envelope be mentioned in the UPGRADE file. Also I'd suggest to remove Envelope::wrap as in b3a6768 as the only reason it exists in core was for this (I'll cherry-pick the commit later).

@Cydonia7 Cydonia7 requested review from dunglas and lyrixx as code owners July 9, 2018 11:42
@Cydonia7 Cydonia7 changed the base branch from 4.1 to master July 9, 2018 11:42
@Cydonia7
Copy link
Contributor Author

Cydonia7 commented Jul 9, 2018

@ogizanagi @sroze I've rebased on master and adapted the ValidationMiddleware in the same way.

@fabpot
Copy link
Member

fabpot commented Jul 19, 2018

@ogizanagi Can you review this PR please?

@fabpot fabpot removed this from the 4.1 milestone Jul 19, 2018
Copy link
Contributor

@ogizanagi ogizanagi left a comment

Choose a reason for hiding this comment

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

That's ok with latest changes 👍
But we miss a mention for the BC break in the UPGRADE file.

@Cydonia7
Copy link
Contributor Author

@ogizanagi I just added a note in the UPGRADE file for 4.2

@fabpot I see you've changed the milestone to 4.1 and next, does this mean this will be inside the next patch or next minor? (If it's patch, then I should move the UPGRADE note)

@sroze
Copy link
Contributor

sroze commented Jul 19, 2018

@Cydonia7 it means it goes to the next release. So 4.2.

UPGRADE-4.2.md Outdated
Messenger
---------

* The `Symfony\Component\Messenger\Middleware\ValidationMiddleware` and `Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware` do not support messages in their `handle` method anymore.
Copy link
Contributor

Choose a reason for hiding this comment

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

We need more than this. I suggest adding something like:

...because they implement the EnvelopeAwareInterface. You need to give them an instance of the Envelope object, wrapping your message. You can use Envelope::wrap($message).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, I just added it.

UPGRADE-4.2.md Outdated
Messenger
---------

* The `Symfony\Component\Messenger\Middleware\ValidationMiddleware` and `Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware` do not support messages in their `handle` method anymore because they implement the `EnvelopeAwareInterface`. You need to give them an instance of the `Envelope` object, wrapping your message. You can use Envelope::wrap($message).
Copy link
Contributor

Choose a reason for hiding this comment

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

Add around theEnvelope::wrap` example.

Also, I think that I'd phrase it like:

The handle method of the X and Y middleware now requires an Envelope object to be given (because they implement the EnvelopeAwareInterface. When using these middleware with the provided MessageBus, you will not have to do anything. If you use the middleware any other way, you can use Envelope::wrap($message) to create an envelope for your message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks a lot better like that.

@sroze
Copy link
Contributor

sroze commented Jul 19, 2018

Thank you @Cydonia7.

@sroze sroze merged commit 9488e2a into symfony:master Jul 19, 2018
sroze added a commit that referenced this pull request Jul 19, 2018
…th a message (Cydonia7)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Messenger] Envelope-aware middleware is never called with a message

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | no
| License       | MIT
| Doc PR        | no

Messenger components middlewares implementing `Symfony\Component\Messenger\EnvelopeAwareInterface` receive in their handle method an instance of `Symfony\Component\Messenger\Envelope`, not a message.

To better reflect the expected usage, I've updated the unit tests for the message middleware and fixed the code accordingly.

Commits
-------

9488e2a [Messenger] Envelope-aware middleware is never called with a message
@Cydonia7 Cydonia7 deleted the envelope-aware-middleware branch July 19, 2018 11:27
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
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