Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed

Conversation

@pamil
Copy link
Contributor

@pamilpamil commentedOct 3, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PRnot yet

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?

@pamilpamilforce-pushed themessenger-command-bus-middleware branch fromd0a42d2 to144ae61CompareOctober 3, 2018 19:48
{
$handler = $this->messageHandlerResolver->resolve($message);

if ($handler instanceof ChainHandler) {

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?

Copy link
Contributor

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? 🤔

Copy link
ContributorAuthor

@pamilpamilOct 6, 2018
edited
Loading

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)));
Copy link
Contributor

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?

pamil reacted with thumbs up emoji
@ogizanagi
Copy link
Contributor

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 ?

@nicolas-grekasnicolas-grekas added this to thenext milestoneOct 14, 2018
@sroze
Copy link
Contributor

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 ?

Sounds reasonable actually. An option and the bus and theMessengerPass to enforce it when registering messages. I'm 👍-ing it!

@sroze
Copy link
Contributor

sroze commentedOct 31, 2018
edited by nicolas-grekas
Loading

Note that nowChainHandler has been removed :) (see#29010)

@Tobion
Copy link
Contributor

Tobion commentedNov 1, 2018
edited
Loading

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 ?

Sounds reasonable actually. An option and the bus and theMessengerPass to enforce it when registering messages. I'm 👍-ing it!

I don't think this is really possible.

  1. You would need to detect that handlers register for overlapping class hierarchies with all the parents and interfaces and wildcard* being taken into account. Does not seem feasible.
  2. It still depends on which messages are dispatched. If I don't dispatch a message at all that could cause several handlers to be executed (maybe it's unused), then there is no problem at all. But you cannot know that at container compilation time.

It would be easy to implement as a new argument in

publicfunction__construct(HandlersLocatorInterface$handlersLocator,bool$allowNoHandlers =false)

@ogizanagi
Copy link
Contributor

@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 :)

  1. You would need to detect that handlers register for overlapping class hierarchies with all the parents and interfaces and wildcard * being taken into account. Does not seem feasible.

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 onMessengerPass::guessHandledClasses might still be valuable.

  1. It still depends on which messages are dispatched. If I don't dispatch a message at all that could cause several handlers to be executed (maybe it's unused), then there is no problem at all. But you cannot know that at container compilation time.

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
Copy link
Member

Closing in favor of#29167, thanks for the PR.

pamil reacted with thumbs up emoji

@stofstof removed this from thenext milestoneNov 23, 2018
@pamilpamil deleted the messenger-command-bus-middleware branchMay 25, 2020 20:20
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

+1 more reviewer

@srozesrozesroze left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@pamil@ogizanagi@sroze@Tobion@nicolas-grekas@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp