Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger] IntroduceSelfStampableInterface#54366

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
VincentLanglet wants to merge2 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromVincentLanglet:selfStambableInterface

Conversation

VincentLanglet
Copy link
Contributor

@VincentLangletVincentLanglet commentedMar 21, 2024
edited by OskarStark
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix #...
LicenseMIT

Idea was kinda suggested from#54141 (comment)
This interface would allow to define stamp I always want by default with a message.

By merging in the order

array_merge($message->getStamps(),$stamps);

I can still override a stamp when dispatching the message.

pounard and norkunas reacted with thumbs up emoji
@carsonbotcarsonbot changed the titleIntroduce SelfStampableInterface[Messenger] Introduce SelfStampableInterfaceMar 21, 2024
@derrabus
Copy link
Member

An alternative idea, also suggested by the comment that you've linked, was to use attributes for stamps. Can you elaborate why you dismissed that idea in favor of an interface?

pounard reacted with thumbs up emoji

@VincentLanglet
Copy link
ContributorAuthor

An alternative idea, also suggested by the comment that you've linked, was to use attributes for stamps. Can you elaborate why you dismissed that idea in favor of an interface?

I misunderstood/forgot about the comment when working on this and the only idea I had in mind was an interface.

Then, I reread the comment and even found#50812
but I'm not sure what would be the interest of attributes here.

IMHO the interface is simpler:

  • A feature with#[DelayStamp(123)] would require to declare every stamps as attributes, you cannot use this for other libs if they don't declare their stamps as attribute.
  • A feature#[AutoStamp(new DelayStamp(123))] solve the previous issue but It still require extra manipulation withReflectionClass when theinstanceof SelfStampableInterface and a getter does all the job.

Also, dynamic stamps would be impossible with attribute.

This would be useful for the LockStamp in#54141,
you could have

class Message implements SelfStampableInterface{     public function __construct(private int $projectId) {}     // With this stamp, I ensure there is never 2 messages for the same Id in the queue     public function getStamps(): array {         return [new LockStamp(self::class . $this->projectId)];     }}

@VincentLanglet
Copy link
ContributorAuthor

VincentLanglet commentedMar 21, 2024
edited by OskarStark
Loading

i tend to prefer stamps as attributes for the sake of decoupling

having runtime flexibility is nice, but IMHO it needs to be scalable, eg. we might want to use additional services to compute a stamp

in that sense, middleware layer already brings full runtime flexibility in userland to apply default stamps

for compiling stamps as-a-service from attributes, take this:

$stampServiceDef = new Definition($attr->getName(), $attr->getArguments());

Sorry, I don't understand how will be solved, in the simple way, the

class Messageimplements SelfStampableInterface{publicfunction__construct(privateint$projectId) {}// With this stamp, I ensure there is never 2 messages for the same Id in the queuepublicfunctiongetStamps():array {return [newLockStamp(self::class .$this->projectId)];     }}

situation with

#[LockStamp()]// Error missing first param.class Messageimplements SelfStampableInterface{publicfunction__construct(privateint$projectId) {}}

@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@VincentLanglet
Copy link
ContributorAuthor

perhaps self-stamping is the way to go for such simple runtime usecases

no strong opinion :)

#[LockStamp()]

it could compute a key from the message payload by default

With a method, you also can add the stamp conditionnaly

public function getStamps(): array {         return $this->foo ? [new FooStamp()] : [new BarStamp()];     }

@derrabus do you have time for a new look ? :)

@VincentLanglet
Copy link
ContributorAuthor

Maybe you have some time for a review@nicolas-grekas ?

@VincentLanglet
Copy link
ContributorAuthor

Friendly ping@derrabus ; would you have time for a review ?

@derrabus
Copy link
Member

Unfortunately not at the moment. 😞

@pounard
Copy link
Contributor

pounard commentedNov 6, 2024
edited
Loading

Looking at this after some time has passed make me think that stamps could simply be attributes on classes, and this would actually make this feature real. All it need it that all stamps extend\Attribute and some outer middleware exist in the dispatcher to expand those as stamps.

Except maybe that it wouldn't allow dynamism in stamp data, do you have any real life use case for such dynamism?

@stof
Copy link
Member

stof commentedNov 7, 2024

Stamps themselves should not be attributes, as they are metadata about a particular message, not about the class. For instance, there are some stamps that are added based on how the message is dispatched or how it is read from the queue.

pounard reacted with thumbs up emoji

@stof
Copy link
Member

stof commentedNov 7, 2024

@ro0NL for applying automatic stamps on messages using a given class, I'd rather have aAutoStamp attribute (name to be bikeshed) taking a Stamp as argument (allowing to repeat the attribute) than making stamps themselves as attributes while stamps themselves cannot always be attributes. It would reduce confusion IMO.

@VincentLanglet
Copy link
ContributorAuthor

Except maybe that it wouldn't allow dynamism in stamp data, do you have any real life use case for such dynamism?

This is a big loss for me. I have some stamp like "DeduplicateStamp" or "DelayStamp" which are added by default (because used 99% of the time) but I need the ability to skip them sometimes. I have also stamp which are added based on the size of the data.

This PR doesn't forbid stamp as attribute, it can still be done in another PR by someone else.

pounard reacted with thumbs up emoji

@pounard
Copy link
Contributor

stampscould be attributes, if the metadata is constant. Otherwise dont apply the stamp as an attribute on your message.

Definitely agree, stamps are basically no more no less than very simple DTOs, exactly what attributes also are in the end.

Whereas@stof is right about the fact thatsome stamps shouldn't be, my opinion is that those which can should directly be attributes. There's no need add an indirection layer here: the most direct implementation would also be the most readable in the end.

@pounard
Copy link
Contributor

This is a big loss for me. I have some stamp like "DeduplicateStamp" or "DelayStamp" which are added by default (because used 99% of the time) but I need the ability to skip them sometimes. I have also stamp which are added based on the size of the data.

OK, I'll stop talking now about attributes, this is not what the issue is about, thanks for answering.

@OskarStarkOskarStark changed the title[Messenger] Introduce SelfStampableInterface[Messenger] IntroduceSelfStampableInterfaceNov 7, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@VincentLanglet
Copy link
ContributorAuthor

Hi@derrabus@ro0NL@stof

It's unclear to me how to move this forward.
Stamp as attribute is a nice feature but should be done in another PR as it's unrealted.
Therefor I don't think there is a current request change here ; it might just require your review then ?

@@ -54,6 +55,10 @@ public function getIterator(): \Traversable

public function dispatch(object $message, array $stamps = []): Envelope
{
if ($message instanceof SelfStampableInterface) {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I didn't find a better place to automatically add thestamp since it's the place where

$envelope = Envelope::wrap($message, $stamps);

is done.

And thenreturn $middlewareIterator->current()->handle($envelope, $stack); is done.

But if I introduce aSelfStampableMiddleware to automatically add the stamp, I cannot be sure:

  • The middleware is used
  • The middleware is the first one

So the same issue would kinda occurs no ?

@VincentLangletVincentLangletforce-pushed theselfStambableInterface branch 4 times, most recently fromd36a59e to7ae6408CompareFebruary 7, 2025 09:48
@VincentLanglet
Copy link
ContributorAuthor

Hi@ro0NL@derrabus I rework the PR to use a middleware, if you want to review again.

Also I wonder if you have a better name in minde thanSelfStampableInterface andAdd SelfStampableStampMiddleware.

@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
@VincentLangletVincentLangletforce-pushed theselfStambableInterface branch 3 times, most recently from8b19b6f toad0e3a1CompareJune 27, 2025 16:02
@norkunas
Copy link
Contributor

This would simplify a lot when using DeduplicateStamp with same message in many places

VincentLanglet reacted with thumbs up emoji

@VincentLanglet
Copy link
ContributorAuthor

This would simplify a lot when using DeduplicateStamp with same message in many places

That's the reason I implemented both ;)

norkunas reacted with thumbs up emoji

@VincentLanglet
Copy link
ContributorAuthor

I might be wrong but it seems like failure is unrelated so@derrabus@ro0NL@stof it's ready to be reviewed.

Friendly ping@OskarStark@nicolas-grekas if you wanna review

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ro0NLro0NLro0NL approved these changes

@derrabusderrabusAwaiting requested review from derrabus

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

10 participants
@VincentLanglet@derrabus@pounard@stof@norkunas@ro0NL@fabpot@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp