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] Pass sender details to SendMessageToTransportsEvent#40152

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

Merged
fabpot merged 1 commit intosymfony:6.2fromJeroeny:sendstamp
Aug 19, 2022

Conversation

@Jeroeny
Copy link
Contributor

@JeroenyJeroeny commentedFeb 11, 2021
edited
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT

This is a feature suggestion that will allow listeners forSendMessageToTransportsEvent to be able to read the sender and sender alias from a sent message.

Use case: To create metrics for messages that go through the system (and especially where to and from). Listener(s) can be created to measure this. They would listen toWorkerMessageHandledEvent,WorkerMessageFailedEvent andSendMessageToTransportsEvent. The first two receive envelopes that contain aReceivedStamp, to determine where the message came from. However, the received envelopes for sent messages do not contain a stamp to read the sender. It would be great if this was possible to do with listener (instead of having to add middleware to each bus).

Approach in this PR: stamp the envelope withSentStamp before dispatchingSendMessageToTransportsEvent.

Alternative approach: pass the info to the event directly:new SendMessageToTransportsEvent($envelope, get_class($sender), $alias). And keep the stamping afterwards.

Edit: I just noticed that one event is dispatched regardless of the number of senders. In that case the event could be dispatched after all the senders have been called (and thus all the stamps set).

@carsonbot
Copy link

Hey!

I had a quick look at this PR, I think it is alright.

I think@ruudk has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@nicolas-grekasnicolas-grekas added this to the5.x milestoneFeb 16, 2021
Copy link
Contributor

@ruudkruudk left a comment
edited
Loading

Choose a reason for hiding this comment

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

TheSendMessageToTransportsEvent is about sending to one or multiple transports (hence plural transports).

TheSentStamp is past tense, meaning it's already sent. When you would pass that to the subscribers listening onSendMessageToTransportsEvent that would be untrue, as the message is not sent yet.

It's different to theReceivedStamp passed to the worker subscribers, in those cases, the message is actually received.

Therefore I think it would be better to do the following:

$senders =$this->sendersLocator->getSenders($envelope);if (null !==$this->eventDispatcher) {$event =newSendMessageToTransportsEvent($envelope,$senders);$this->eventDispatcher->dispatch($event);$envelope =$event->getEnvelope();}foreach ($sendersas$alias =>$sender) {$this->logger->info('Sending message {class} with {alias} sender using {sender}',$context + ['alias' =>$alias,'sender' =>\get_class($sender)]);$envelope =$sender->send($envelope->with(newSentStamp(\get_class($sender),\is_string($alias) ?$alias :null)));}

This way:

  • you still only emit 1 event
  • the event now contains all the senders
  • the envelope passed to the subscribers is still the same

@Jeroeny
Copy link
ContributorAuthor

@ruudksendersLocator->getSenders() returnsiterable (sometimes a\Generator). I tried your suggestion, but loading all the senders and aliases into an array got a bit complex. I agree that there's still some improvement to gain here though.

@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@fabpot
Copy link
Member

What's the status of this PR?@Jeroeny Are you still interested in moving it forward?

@Jeroeny
Copy link
ContributorAuthor

Yes I'd be willing to move this forward. The last time I hit kind of a dead-end in which approach to take. Would ruudk's suggestion be desired for example?

@fabpot
Copy link
Member

I think@ruudk's suggestion makes a lot of sense.

@Jeroeny
Copy link
ContributorAuthor

In their snippet,$senders is usually a\Generator. To pass it toSendMessageToTransportsEvent, should this be converted to an array (losing thealiases or risk of losing entries due to duplicate array-keys which Generators allow) ? Or be passed as-is, which will cause problems when reading the variable, because the sending logic will not get those values from the Generator too ? Or callgetSenders() twice, which also seems undesirable.

@fabpot
Copy link
Member

What would be the use case for having two entries with the same alias?

@Jeroeny
Copy link
ContributorAuthor

I don't think there is, but I thought it was technically supported and could cause issues. Anyway, I've implemented the suggested approach 👍 .

@fabpot
Copy link
Member

Thank you@Jeroeny.

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

Reviewers

@fabpotfabpotfabpot approved these changes

@srozesrozeAwaiting requested review from sroze

+1 more reviewer

@ruudkruudkruudk left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

5 participants

@Jeroeny@carsonbot@fabpot@ruudk@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp