-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger][DX] Allow stamps to be passed directly to MessageBusInterface::dispatch() #30707
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.
The anonymous class implementing MessageBusInterface
in src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/Fixtures/long_receiver.php
needs to be updated as well.
I find it confusing: my original assumption would have been that the other arguments are other messages, in case I want to dispatch multiple of them at the same time. I know it's been done this way on This is much more explicit: $bus->dispatch(
new Envelope(new SendSmsNotification('Hi!'))
->with(new DelayStamp(10), new QueueNameStamp('low'))
); Or if it's really important, let's make it an array so we identify easily that it should not be other messages? $bus->dispatch(
new SendSmsNotification('Hi!'),
[ new DelayStamp(10), new QueueNameStamp('low') ]
); |
a5d19c3
to
90c48c4
Compare
Hmm, fair point. Wrapping it in an array still looks great to me, and indeed, a bit more clear. I can change to use that if others agree. |
I agree that using an array. looks a bit better. |
I suggest we change the |
90c48c4
to
de66f8c
Compare
de66f8c
to
3271b0d
Compare
This is ready to go:
|
0b16b9a
to
a995c48
Compare
Rebased & ready again |
Thank you @weaverryan. |
…MessageBusInterface::dispatch() (weaverryan) This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger][DX] Allow stamps to be passed directly to MessageBusInterface::dispatch() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | TODO Me again o/! This proposal is *purely* for DX. With `DelayStamp`, the proposal of QueueNameStamp and future things like `AmqpRoutingKeyStamp`, stamps are becoming more common for end users to use. This changes how it looks to use them: ```php // before $bus->dispatch(new Envelope(new SendSmsNotification('Hi!'), new DelayStamp(10), new QueueNameStamp('low'))); // after $bus->dispatch(new SendSmsNotification('Hi!'), [new DelayStamp(10), new QueueNameStamp('low')]); ``` It's definitely a BC break, which is allowed because the component is experimental, though it should be minimized. This BC break shouldn't be felt by most end users, as creating your own bus is an advanced use-case. Even if you decorated it, you'll get an obvious error. Commits ------- e861de7 Allow stamps to be passed directly to MessageBusInterface::dispatch()
🤞 fixed failing tests in fd4146c. |
@weaverryan I want to have clear bus interface, that clear purpose is to send a message. This configuration shows what message is sent and how it should be treated. Implementing this will force my class to 2 things - create the message and send them. "preoccupied with whether or not they could, they didn't stop to think if they should." I think the original way was showing the better purpose of this functionality. Now is a blurred. |
Hi! I don’t quite understand. We added an optional argument to the interface. Are you creating a class that implements this interface and the new argument causes you a problem? Or does the new optional argument cause an issue when you are using the interface? Cheers! |
if anything; we have 2 ways to do the same thing, as shown by the PR description. Not sure it's desired either 😕 currently messenger exposes a As a vendor i might only care about "provide a message we can dispatch" (wether it's an envelope with stamps is a detail). But now the user might want to provide "a message" and "stamps", which as a vendor, i need to accept yes/no. This is diversity happening :) |
@weaverryan That is my opinion. To keep more to KISS rule ;) For
And for the general message, we have 3 ways to send it with message
message + array stamps
envelope + array stamps
envelope with stamps
|
|
the nice thing is I've no real issue with the change. Personally i like Comparing this to a real life scenario; can we pass a message/envelop and its stamps separate to a mail deliverer? Wouldnt they expect a stamped message/envelop instead? |
Ha! Indeed. But what I would personally really like is for the mail deliverer to come to my house, put the items in the envelope for me, close it, put the stamps on, then take it to the post office. That's a bit outside of the scope of what their job should be perhaps, but it would be awesome! Even in the real world scenario, there's a balance between purity and having a great customer experience (neither should dominate). |
I really like your example, but I see this very straightforward. For a simple message:
you have:
If you want advanced use, then you simply use This change simply provides something between that is neither of these solutions and don't give use real advantage - only more blurred interface:
@nicolas-grekas I always like I simply want to keep it simple stupid:
|
exactly, it shows multiple concerns. Not an issue per se, but has its cost. In real life this is called Franking. This also comes with a trust issue, some trust this to go right, others dont and stamp themselves. Hence i think this leads to diversity. The question is; if we pass an "envelop/message" and "stamps" separate, can we assume it will be franked implicitly? Im not sure it's obvious. Ultimately i believe a message should be stamped before it can be dispatched :/ |
Honestly, I lost track of what is discussed here. |
the "design philosophy" itself still :) (moving the stamping concern to the dispatching side) |
it always has been on the dispatching side, so this is old :) |
before we didnt stamp in dispatch() at least - $envelope = $message instanceof Envelope ? $message : new Envelope($message);
+ $envelope = Envelope::wrap($message, $stamps); |
Semantically, this is strictly the same. There is a bijection between both styles:
I see why the 1st style has been added. There is no technical reason not to do it. |
* @param object|Envelope $message | ||
* @param StampInterface[] $stamps | ||
*/ | ||
public static function wrap($message, array $stamps = []): self |
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.
@weaverryan wouldnt stamp() be the better name? In case of explicit public usage ...
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.
to clarify; if wrapping means "put it in an envelop" this method doesnt always "wrap", whereas new Envelope($anything)
does.
This method wraps if needed, but always stamps.
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.
So, are you suggesting a change? Or is it clear for you now?
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.
It stamps only if stamps are provided.
The main use case is removing the "if" that the method contains from userland boilerplate.
Tldr, wrap() fits my mind :)
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 it might fit; "we wrap it with stamps" :/ but to me that's "stamping", not "wrapping" (stamping requires an envelope wrap)
Just curious if wrap() and __construct() could be considered confusing...
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.
It stamps only if stamps are provided.
hm indeed, missed this detail :} OK. these technical details are hard to convey with naming :) let's keep as is 👍
@nicolas-grekas If you insist that they are the only use cases, then that you are correct. This would be correct. The original:
and
Semantically, this is strictly the not same. This led to ignoring the first use case. As mentioned here, I gave you my arguments. Is there any argument, that could convince you? Maybe, but not mine. If my arguments didn't convince you, my job here is done. |
Me again o/!
This proposal is purely for DX. With
DelayStamp
, the proposal of QueueNameStamp and future things likeAmqpRoutingKeyStamp
, stamps are becoming more common for end users to use. This changes how it looks to use them:It's definitely a BC break, which is allowed because the component is experimental, though it should be minimized. This BC break shouldn't be felt by most end users, as creating your own bus is an advanced use-case. Even if you decorated it, you'll get an obvious error.