8000 [WIP] [Messenger] Locate exactly one handler by gquemener · Pull Request #40254 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP] [Messenger] Locate exactly one handler #40254

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

Conversation

gquemener
Copy link
Contributor
@gquemener gquemener commented Feb 19, 2021

Related to #36958

Q A
Branch? 5.x for features
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #36958
License MIT
Doc PR symfony/symfony-docs#...

The main idea is to allow definition of a command bus which helps developper detect the following misconfigurations:

  • No command handler has been defined for a given command
  • Many command handlers has been defined for a given command

Today, only the first case can be detected (this is the default behaviour of the HandleMessageMiddleware), the second one is not (instead, all the command handlers will be called).

@gquemener gquemener requested a review from sroze as a code owner February 19, 2021 13:10
@gquemener gquemener changed the title [Messenger] Locate exactly one handler [WIP] [Messenger] Locate exactly one handler Feb 19, 2021
@nicolas-grekas nicolas-grekas added this to the 5.x milestone Feb 22, 2021
$this->handlers = $handlers;
}

public function getHandlers(Envelope $envelope): iterable
Copy link

Choose a reason for hiding this comment

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

Does this need a dock-block?

    /**
     * {@inheritdoc}
     *
     * @throws NoHandlerForMessageException When no handler is found class
     */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll fix all CS if this feature gets interest. Thanks for pointing it out 👍


public function getHandlers(Envelope $envelope): iterable
{
$type = \get_class($envelope->getMessage());
Copy link

Choose a reason for hiding this comment

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

nit pick: This variable is named $class is similar function. e.g. HandlersLocator.php line 69

{
$type = \get_class($envelope->getMessage());
if (!isset($this->handlers[$type])) {
throw new NoHandlerForMessageException($type);
Copy link

Choose a reason for hiding this comment

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

8000

Shouldn't the error message include the message type, rather that the type/class name

throw new NoHandlerForMessageException($this->handlers[$type]);

Theory being the error message 'Multiple handlers for message "%s"', thus, does this mean $envelope->getMessage()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this specific case, $type holds the message type and $this->handlers[$type] is not set.

Theory being the error message 'Multiple handlers for message "%s"', thus, does this mean $envelope->getMessage()?

I don't understand what you mean.

@gquemener
Copy link
Contributor Author

Superseded by #43300

@gquemener gquemener closed this Oct 5, 2021
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.

[Messenger] Provides a safe single handler strategy
4 participants
0