8000 [Messenger] Add auto stamp attribute and middleware by KerianMM · Pull Request #50812 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Add auto stamp attribute and middleware #50812

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

Open
wants to merge 2 commits into
base: 7.3
Choose a base branch
from

Conversation

KerianMM
Copy link
Contributor
@KerianMM KerianMM commented Jun 28, 2023
Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #50800
License MIT
Doc PR symfony/symfony-docs#18461

Add AutoStamp attribute on message and configure messenger to enable AutoStampMiddleware to automatically add stamps on message.
No needs to pass them when dispatch message.

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@KerianMM KerianMM force-pushed the messenger-auto-stamp branch 2 times, most recently from d4e67bc to b5a964f Compare June 28, 2023 13:10
@KerianMM KerianMM marked this pull request as ready for review June 28, 2023 13:25
@carsonbot carsonbot added this to the 6.4 milestone Jun 28, 2023
@derrabus
Copy link
Member

Maybe it's a stupid idea, but are there arguments against using stamps as attributes directly?

#[AutoStamp(new DelayStamp(123))]
#[AutoStamp([new ValidationStamp(['Default', 'Extra'])])]
class AutoStampedMessage
{
}

Vs.

#[DelayStamp(123)]
#[ValidationStamp(['Default', 'Extra'])]
class AutoStampedMessage
{
}

@KerianMM KerianMM force-pushed the messenger-auto-stamp branch from b5a964f to 89fb4e5 Compare June 28, 2023 15:30
@KerianMM KerianMM requested a review from kbond as a code owner June 28, 2023 15:30
@KerianMM
Copy link
Contributor Author

It's done, i'm not sure about second commit
Should we really tag all stamps as class attributes ? Are they really all repeatable ?

@kbond
Copy link
Member
kbond commented Jun 28, 2023

Maybe it's a stupid idea, but are there arguments against using stamps as attributes directly?

I think I'm in favor of @derrabus' idea. This allows 3rd party stamps that aren't attributes to be used.

8000
@Nyholm
Copy link
Member
Nyholm commented Jun 28, 2023

Interesting. Thank you for this PR.

Maybe it's a stupid idea, but are there arguments against using stamps as attributes directly?

It is the dispatcher that is smart, it knows how long a message should be delayed. It should not be the receiver nor the message itself.

If we add this kind of configuration on the message, how do a dispatcher opt out? Or how can a dispatcher change the config, Say delay for 10s instead of 5s? (think retry middleware).

I think we open a can of worms.. What is the reason for adding auto-stamps or adding stamps to the message directly?
If it is only syntax sugar, then I would prefer keep it explicit as we do now.

@derrabus
Copy link
Member
derrabus commented Jul 4, 2023

It is the dispatcher that is smart, it knows how long a message should be delayed.

No, the dispatcher should stay dumb. Adding stamps based on attributes (however those might look like) can and should be done by a middleware.

Or how can a dispatcher change the config, Say delay for 10s instead of 5s? (think retry middleware).

The sttributes on the message should be a default. The retry middleware needs be able to override those defaults.

What is the reason for adding auto-stamps or adding stamps to the message directly? If it is only syntax sugar, then I would prefer keep it explicit as we do now.

Yes, it is syntactic sugar for wiring a piece of middleware that always adds the same stamps to a specific message class.

@KerianMM
Copy link
Contributor Author

I see it like defaults too.
Maybe the middleware should be smarter and read other stamps to apply attributes stamps on the envelope ?

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@VincentLanglet
Copy link
Contributor

With the current implementation, if I write

$bus->dispatch(new MyMessage(), [new DelayStamp(5)]);

and the MyMessage has a DelayStamp attribute ;
wouldn't the new DelayStamp(5) overridden by the attribute of the message in the middleware ?

I would expect the opposite, the attribute should be a "default" but can be overriden when dispatching the message.

I just thought/wanted a similar feature and tried to introduce a SelfStampableInterface in
#54366 dunno if it's a better/simpler solution ?

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
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] Stamps as Attributes on message class
9 participants
0