-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Fix return senders based on the message parents/interfaces #27184
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
[Messenger] Fix return senders based on the message parents/interfaces #27184
Conversation
I'm not sure this is a good idea, is it? |
I foresee it being a burden to declare all the messages you want sent in your config. This would alleviate that. |
But this makes it impossible to opt-out from a handler while implementing an interface or extending a base message class. This feels a lot like global interface-based configuration, which is a no-go. |
Yeah, I understand what you're saying. I have thought of alternative solutions that would work within the current implementation. |
That's for senders, not handlers. Also you can opt-out by specifying the specific message class on the routing configuration as classes take precedence over interfaces in SenderLocator. |
|
Is the same issue blocker applicable to wildcard |
For the record, this is what it would allows: framework:
messenger:
transports:
amqp: ...
aws: ...
routing:
App\Message\AMQPMessageInterface: amqp
App\Message\AWSMessageInterface: aws from here, all my messages that need to be send through amqp transport will implement |
But I understand what @nicolas-grekas says too and probably this goal should be reached in another way around... |
OK, I get it better now. I'm removing my -1 above, this may actually be a good idea: this is configuration-based already and senders are not bound by messages' interfaces. The issue here is finding which sender to select for a given message, and when no sender is explicitly defined, falling back to interfaces then I then have a question: what about parent classes? e.g VarDumper's AbstractCloner checks them before: Don't we want to do the same here? |
966ebb1
to
0ac140a
Compare
Parent classes supports added. |
0ac140a
to
8b8100c
Compare
We should be clear that this is a fallback: when no sender exists for a given class, we check the parents. One could expect that when a sender is registered for a given interface, it gets all the messages from that type even if a class-specific sender is also configured. Correct ?
Note that I feel like this kind of dispatching should be avoided: messages should be independent of the sender that may handle them, isn't it? The interface should be semantic instead, allowing to label message by "kinds", and not by infrastructure component. |
Indeed...
Sorry I'm not sure to understand your statement very well...
It's just an example, but I guess it depeds of how many senders you have and how many senders are handling the same kind of messages. |
$container->set('my_amqp_sender', $sender); | ||
|
||
$locator = new SenderLocator($container, array( | ||
DummyMessage::class => array( |
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.
Can you configure it here so that the interface is the first argument of the locator to prove that the parent class takes precedence on the interface?
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.
Done.
|
||
private function getSenderIds($message): array | ||
{ | ||
$senderIds = array(); |
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'm not sure you need that variable anymore, you can use return
s directly.
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.
Indeed.
), | ||
)); | ||
|
||
$this->assertEquals(array($sender), $locator->getSendersForMessage(new ChildDummyMessage('Hello', array('name' => 'World')))); |
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.
assertSame
for all the occurrences of assertEquals
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.
Fixed.
|
||
class ChildDummyMessage extends DummyMessage | ||
{ | ||
private $extra; |
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 don't see you using that extra so I guess it can be removed.
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.
Removed extra code.
12c0f65
to
88375f5
Compare
Status: Needs Review |
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.
Looks good to me 👍
88375f5
to
41e25ab
Compare
Rebased. |
Thank you @yceruto. |
…s/interfaces (yceruto) This PR was merged into the 4.1 branch. Discussion ---------- [Messenger] Fix return senders based on the message parents/interfaces | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - https://github.com/symfony/symfony/blob/c3d4536203981d425adc47552c553a9633186a5e/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1494-L1499 According to the code a message interface is supported into routing configuration, but it doesn't work when `SendMessageMiddleware` gets the mapping senders for the current object message. This PR tries to fix it. Commits ------- 41e25ab Fixed return senders based on the message parents/interfaces
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Lines 1494 to 1499 in c3d4536
According to the code a message interface is supported into routing configuration, but it doesn't work when
SendMessageMiddleware
gets the mapping senders for the current object message.This PR tries to fix it.