Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Messenger] Add middleware allowing just for a single handler#28716
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
7088a74 tod0a42d2Compared0a42d2 to144ae61Compare| { | ||
| $handler = $this->messageHandlerResolver->resolve($message); | ||
| if ($handler instanceof ChainHandler) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I feel like this is tight coupling to a specific implementation: any other handler could implement a chained behavior, isn't it?
Why do we want to restrict the possibilities here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yes, this is coupled with theFrameworkBundle implementation. Unfortunately, I don't have any idea on how to make it better (I don't think that sharing the YAML configuration is better either).@nicolas-grekas do you have an idea? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, I also don't think this is the best solution, but I couldn't think of any other way (apart from introducing such a constraint intoFrameworkBundle itself).
We want to restrict it only to one handler to prevent any issues with having two handlers handling the same command (which could happen by accident, especially if using autowiring and autoconfiguration).
| $handler = $this->messageHandlerResolver->resolve($message); | ||
| if ($handler instanceof ChainHandler) { | ||
| throw new MoreThanOneHandlerForMessageException(sprintf('More than one handler for message "%s".', \get_class($message))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The other "problem" (or challenge) with the current implementation is that we can't display which are the implementations. It would massively help the developer, isn't it?
ogizanagi commentedOct 8, 2018
I wonder if running this check at runtime for each message dispatched really makes sense. It's not runtime dependent at all (hence, not really valid as a middleware), so perhaps we should rather just make it a bus option ? |
sroze commentedOct 21, 2018
Sounds reasonable actually. An option and the bus and the |
sroze commentedOct 31, 2018 • edited by nicolas-grekas
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by nicolas-grekas
Uh oh!
There was an error while loading.Please reload this page.
Note that now |
Tobion commentedNov 1, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't think this is really possible.
It would be easy to implement as a new argument in
|
ogizanagi commentedNov 1, 2018
@Tobion : Sure, this comment is outdated and was referring to another era where the ChainHandler existed and everything was guessed at compilation-time. Perhaps you're right :)
Well, if you want to add this check, (I guess) you're likely to use simple objects without inheritance nor interface in your bus. This check at compilation-time based on
If it's not used, then it should have been removed? This check isn't for a particular message, but for the whole bus. (I mean you're not asking if there is an issue with a specific message but if there isn't one in the whole bus which may be mis-configured). |
nicolas-grekas commentedNov 15, 2018
Closing in favor of#29167, thanks for the PR. |
Uh oh!
There was an error while loading.Please reload this page.
It's a quite common middleware, required for command buses.
PS. How do you manage to have autocompletion for PHPUnit classes when writing tests in Symfony since there is no PHPUnit in dependencies?