-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] allow specifying the topic when calling dispatch() #28944
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
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.
As this dispatching key would mainly be used for the two use cases mentioned beforehand, do we really need to expose $key
in the MessageBusInterface::dispatch()
signature rather than letting users to stamp themselves when needed?
I think so yes: looking at e.g. EventDispatcher interface, this dispatching key is decoupled from the concept of an |
3c837db
to
ffc553b
Compare
|
ffc553b
to
292ec4a
Compare
good catch, fixed thank. |
7acc671
to
9c3d5b0
Compare
PR rebased and updated: getDispatchKey now always returns a key, and senders and handlers locators get only this key as argument. This makes the type-based dispatching an implementation detail of the locators' behavior, as it should. This resolves the discussion above with @ro0NL. |
9c3d5b0
to
2edb4bc
Compare
src/Symfony/Component/Messenger/Handler/Locator/AbstractHandlerLocator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Transport/Sender/Locator/AbstractSenderLocator.php
Outdated
Show resolved
Hide resolved
* | ||
* @final | ||
*/ | ||
protected function dispatchMessage($message) | ||
protected function dispatchMessage($message, string $key = null): void |
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.
you forgot to update $key here
b70d176
to
eabea8a
Compare
i'd say $messageKey, which to me implies an "address" already. Somehow "address" feels less intuitive to me, as its implementation is just a "key". key over name might imply "is unique", thus an address. |
We thought about |
The handler is the recipient of the message which is exactly the purpose of an adding an address. I cannot follow your argument. |
IMHO, "address" is pushing the metaphor a bit too far. There is a difference here with postal routing: the dispatcher doesn't want to target a specific handler/sender. It just dispatches a name - and then - maybe - a sender/handler will subscribe to the topic. |
what about $topic+getTopic()? |
eabea8a
to
390d5ee
Compare
390d5ee
to
bd0ced5
Compare
PR rebased, now using the word "topic" - it makes so much sense to me. |
bd0ced5
to
3156b9c
Compare
I think that I prefer |
Honestly I don't get why: topic is much easier to explain/teach. It's just the correct word for what we need here. Thesaurus suggests "subject" as a synonym. Not sure it's better than topic. |
I don't really like
Then we could just call it |
I think that's too bad that AMQP pollutes the selection of the proper English word. Ignoring it, "topic" is really what this is about to me. Like "the thing the message is about" - ie it's "topic". "Routing key" is going to be as hard to teach as "message name" to me - and is directly imported from AMQP context this time. Personally, I wouldn't consider that the AMQP vocabularies should influence ours. What do others think? Maybe @weaverryan? topic - subject - name - class - theme - etc |
Would using topic really be any confusing? We could use $messageTopic / getMessageTopic() instead of just $topic / getTopic(), would that make it acceptable? |
7911c08
to
c73189a
Compare
PR updated to account for the new vocabulary in service configuration, with some cleanups found meanwhile. I suggest to proceed with the word "topic" - currently I'm blocked with 3 PRs waiting for this to be resolved. We can always change later. |
I agree with @nicolas-grekas on the word "topic". In RabbitMQ the word is only used to define the type of the exchange. IMHO they could have named it |
c73189a
to
2bb18a7
Compare
2bb18a7
to
5d16e85
Compare
Topic to me means a message can have several topics. It's similar to tags and allows to categorize things. But here it's just a string and not an array for some reason. And there is not way to match parts of the topic string currently. |
Closing: talking with Ryan, we found a way to use interfaces for topics. But not the current way, which is totally broken. I'm on a PR. |
When dispatching a message, it's not always possible to know its "class" beforehand. Currently, the component suffers from this limitation of not allowing one to dispatch messages based on a string that would be provided at runtime.
Dispatching by parent classes + interfaces looks like a workaround for this limitation to me. Binding the type-system and configuration is what made autowiring clumsy in 2.8. The issue was that changing/refactoring some code would have unrelated and unwanted side effects. Here, that'd be the same on the way messages are dispatched. Adding a dispatch key fixes this issue by allowing one to opt-out from type-based dispatching, without removing this strategy (time will tell if I'm wrong)
Anyway, allowing to provide a runtime-computed dispatch key is a missing core feature.
It allows both: