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] AddTransportNamesStamp to change the transport while dispatching a message#39306

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

Conversation

@abarkine
Copy link
Contributor

@abarkineabarkine commentedDec 4, 2020
edited by OskarStark
Loading

QA
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#38200,Fix#39306
LicenseMIT
Doc PRsymfony/symfony-docs#17113

This feature will allow developers to choose transport layer while dispatching a message. Normally, we define transport layer in configuration. As a result, developer doesn't have any power to modify it after the deployment. This PR aims to allow overriding already defined transport layer for a message and rerouting it to different transport per dispatch request.

If newly added stamp is not used, default configuration will be used for choosing transport.

Since I've added a new stamp, there shouldn't be any BC change.

Jeroeny, chapterjason, tomcizek, pdoreau, arnedesmedt, curry684, damienalexandre, and emmanuelballery reacted with thumbs up emoji
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@jderussejderusse added this to the5.3 milestoneDec 4, 2020
Copy link
Member

@jderussejderusse left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution.

What if people want keeping the original senders?.

I wonder if we couldn't use something similar to theBusNameStamp:

  • use a middleware that initialize the envelope with aSenderNamesStamp
  • send the envelope to the senders contained in the lastSenderNamesStamp

@abarkine
Copy link
ContributorAuthor

BusNameStamp and using middleware to insert Stamp

Wouldn't it add an overhead? In current way, Envelope will not include OverrideStamp if not necessary. What do you think?

@diimpp
Copy link
Member

diimpp commentedDec 5, 2020
edited
Loading

On naming note, public stamp name shouldn't be derived from this moment internal implementation, so something likeSendersOverride is not very suitable in my opinion.

As library user, who is not privy to all the internals, first naming choice would beTransportRouteStamp, but I do see that therouting is the framework-bundle config concept, rather than messenger concept, so maybeTransportSendersStamp

@abarkine
Copy link
ContributorAuthor

On naming note, public stamp name shouldn't be derived from this moment internal implementation, so something likeSendersOverride is not very suitable in my opinion.

As library user, who is not privy to all the internals, first naming choice would beTransportRouteStamp, but I do see that therouting is the framework-bundle config concept, rather than messenger concept, so maybeTransportSendersStamp

@diimpp , thanks for your input, I will change the name, what do you think about the implementation?

@diimpp
Copy link
Member

diimpp commentedDec 7, 2020
edited
Loading

@asilelik looks alright to me, but I'm not a messenger specialist.

One more thing, I don't why there are multiple senders routing in the messenger and what is the use case, but maybe you will want to allow to have both behaviors to override/extend senders config with bool flag at Stamp class.

@abarkine
Copy link
ContributorAuthor

@asilelik looks alright to me, but I'm not a messenger specialist.

One more thing, I don't why there are multiple senders routing in the messenger and what is the use case, but maybe you will want to allow to have both behaviors to override/extends senders config with bool flag at Stamp class.

Do you mean to send envelope to both configured transport and overridden one?

@diimpp
Copy link
Member

@asilelik looks alright to me, but I'm not a messenger specialist.
One more thing, I don't why there are multiple senders routing in the messenger and what is the use case, but maybe you will want to allow to have both behaviors to override/extends senders config with bool flag at Stamp class.

Do you mean to send envelope to both configured transport and overridden one?

For example if somebody already have their transports setup, but want conditionally to specifyaudit transport for certain messages.

Then they will want to keep their original transports list and just add another one, e.g.new TransportSendersStamp(['audit'], $extendSenders = true)

My personal use case is quite different, I need to conditionally send messeges to sync or async transports, so I will need to override original transports routing if preset, e.g.new TransportSendersStamp(['async'], $overrideSenders = true)

@abarkine
Copy link
ContributorAuthor

@asilelik looks alright to me, but I'm not a messenger specialist.
One more thing, I don't why there are multiple senders routing in the messenger and what is the use case, but maybe you will want to allow to have both behaviors to override/extends senders config with bool flag at Stamp class.

Do you mean to send envelope to both configured transport and overridden one?

For example if somebody already have their transports setup, but want conditionally to specifyaudit transport for certain messages.

Then they will want to keep their original transports list and just add another one, e.g.new TransportSendersStamp(['audit'], $extendSenders = true)

My personal use case is quite different, I need to conditionally send messeges to sync or async transports, so I will need to override original transports routing if preset, e.g.new TransportSendersStamp(['async'], $overrideSenders = true)

Good point. It will make SendersLocator class a bit complex but I guess it will add a great value to the Stamp.

diimpp reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas modified the milestones:5.3,5.xDec 8, 2020
@abarkine
Copy link
ContributorAuthor

@jderusse , can you take a second look at this PR and comment on suggestions? If you are fine with current implementation, I will create the tests to finalize PR.

@r6rob
Copy link

My use case is very similar to@diimpp. Building a job queue and would love to specify whether a job will be handled as sync or async programatically.

This would be very helpful, eagerly awaiting PR.

chapterjason, tomcizek, magnetik, and skolman reacted with thumbs up emoji

@fabpotfabpot modified the milestones:5.4,6.1Nov 16, 2021
@chalasr
Copy link
Member

@asilelik Thank you for the PR. Please go ahead with the missing tests, this looks good to me.

abarkine and r6rob reacted with heart emoji

@abarkine
Copy link
ContributorAuthor

@chalasr I've added the test. Apart fromgit rebase error, how can I fix other failures? They don't seem like related errors to my PR.

@chalasr
Copy link
Member

Yes, the failing test is unrelated.

@abarkine
Copy link
ContributorAuthor

@chalasr what is the preferred way for getting rid of merge commit? Can I force push or is there any other suggestion?

@chalasr
Copy link
Member

I missed that Jérémy's comment, thanks.

What about conflicting when both are sent?

Given the originally proposed name, I suppose one may want to configure the sender the regular way and use the stamp to change the sender under certain circumstances only.
Maybe the stamp could take a flag controlling whether to replace existing senders or not?

@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@tg-mvooges
Copy link

tg-mvooges commentedJul 18, 2022
edited
Loading

if we only look at the stamp, it's less clear to me that adding one ViaSenderStamp is going to erase all senders set via the framework config

This maps to@jderusse's comment:

What if people want keeping the original senders?.

What about conflicting when both are sent? Aka throw if a sender is configured while the stamp is also used? That'd make the situation impossible.

I've not read the full thread (just the last few messages) but I would not for for a "when both are set". I would expect an either/or situation: You either use the default symfony-sender-decider-logic, OR the specified ones. If you would override the default configed target queue via a Stamp I think that could be made obvious with a clear name.

To add a little insight on how we would like to use this: We have a few microservices which listen to the queue via the normal config. The failed messages all get send to a central located microservice which has logic to place them back on their respective queues.
But that could be any queue, the central micro doesnt perse know everything. It has to now, which is inconvinient

@TCM-dev
Copy link

TCM-dev commentedAug 4, 2022
edited
Loading

I'm also of the opinion that this should either use the default configured ones OR the specified ones (which I believe makes sense with the stamp nameOverrideSendersStamp)

I personnaly need this because in my application, I need to have the same message/handler to have a different priority depending on some context. (I can provide real world example if needed)

Unless I'm mistaken, the only way I could do this right now would require me to duplicate the message/handlers with another name and configure them with another transport which is not ideal.

Adding one stamp to decide if a message has an higher priority than another on the fly makes perfect sense to me and I was persuaded that it was actually a feature in messenger.

Are the unsuccessful checks the only things preventing this to be merged or is this still open to discussion?

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

I've rebased this PR and made some naming changes to finish it.

abarkine reacted with thumbs up emoji
@fabpotfabpotforce-pushed thefeature/define-transport-dynamically branch 2 times, most recently fromadfbd37 to1a5f229CompareAugust 4, 2022 15:15
@tg-mvooges
Copy link

I've rebased this PR and made some naming changes to finish it.

I'm not 100% sure, but does this now ADD senders instead of overwriting? That might be slightly limiting. Not for my case, but supose you have a message default send to queueA and you want to CHANGE that to queueB. If you can only ADD, that might be problematic. Using an Override of some kind might be a more broad solution. Or some other method to reset the current senders.

Again, doesnt bother me, I'm looking forward for this feature either way ^_^

diimpp reacted with thumbs up emoji

@fabpotfabpotforce-pushed thefeature/define-transport-dynamically branch from1a5f229 to239ea41CompareAugust 4, 2022 15:25
@fabpot
Copy link
Member

@tg-mvooges That's the case. Seehttps://github.com/symfony/symfony/pull/39306/files#diff-357beebf345f58f777f74eb1127331b8107de09438ff78435093085a531c52beR52, if the stamp is set, we return and bypass the default configuration. Did I miss something?

@fabpotfabpot changed the title[Messenger] Add functionality for choosing transport while dispatching message[Messenger] AddSenderNamesStamp to change the transport while dispatching a messageAug 4, 2022
@TCM-dev
Copy link

@tg-mvooges That's the case. Seehttps://github.com/symfony/symfony/pull/39306/files#diff-357beebf345f58f777f74eb1127331b8107de09438ff78435093085a531c52beR52, if the stamp is set, we return and bypass the default configuration. Did I miss something?

Looks perfect to me and more consistent with other stamp names.
I'm just wondering if "sender" is the correct word, the documentation talks about "transport", this issue talk about being able to change "transport" and yet we name it sender.
I may be wrong but wouldn't it be even better if it was named TransportsStamp/TransportNamesStamp ?

@fabpotfabpotforce-pushed thefeature/define-transport-dynamically branch from239ea41 tobffb292CompareAugust 4, 2022 18:42
@fabpot
Copy link
Member

@tg-mvooges That's the case. Seehttps://github.com/symfony/symfony/pull/39306/files#diff-357beebf345f58f777f74eb1127331b8107de09438ff78435093085a531c52beR52, if the stamp is set, we return and bypass the default configuration. Did I miss something?

Looks perfect to me and more consistent with other stamp names. I'm just wondering if "sender" is the correct word, the documentation talks about "transport", this issue talk about being able to change "transport" and yet we name it sender. I may be wrong but wouldn't it be even better if it was named TransportsStamp/TransportNamesStamp ?

Even if Sender is the right word, I think you're right that using Transport is easier to understand. Updated accordingly.

@fabpotfabpotforce-pushed thefeature/define-transport-dynamically branch frombffb292 tod9f1254CompareAugust 4, 2022 18:44
@fabpotfabpot changed the title[Messenger] AddSenderNamesStamp to change the transport while dispatching a message[Messenger] AddTransportNamesStamp to change the transport while dispatching a messageAug 5, 2022
@fabpotfabpotforce-pushed thefeature/define-transport-dynamically branch fromd9f1254 toc47334eCompareAugust 5, 2022 06:03
@fabpotfabpotforce-pushed thefeature/define-transport-dynamically branch fromc47334e tof526af0CompareAugust 5, 2022 06:45
@fabpot
Copy link
Member

Thank you @asilelik.

abarkine reacted with heart emoji

@fabpotfabpot merged commit1a4a5d5 intosymfony:6.2Aug 5, 2022
fabpot added a commit that referenced this pull requestAug 7, 2022
…ally (fabpot)This PR was merged into the 6.2 branch.Discussion----------[Mailer] Add a way to change the Bus transport dynamically| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets       |Fix#36348 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License       | MIT| Doc PR        |This PR relies on#39306. Once merged, this PR will be rebased.This allows overriding the bus transport "dynamically" via the `X-Bus-Transport` header.Commits-------ffe3600 [Mailer] Add a way to change the Bus transport dynamically
@tg-mvooges
Copy link

@tg-mvooges That's the case. Seehttps://github.com/symfony/symfony/pull/39306/files#diff-357beebf345f58f777f74eb1127331b8107de09438ff78435093085a531c52beR52, if the stamp is set, we return and bypass the default configuration. Did I miss something?

Ah, with the focus on that snippet, yes that seems perfect! I'm fairly new to this message concept, I'm still getting used to this 'Stamps' logic and how it works. Great feature coming up, looking forward to be able to use it, good job!

@fabpotfabpot mentioned this pull requestOct 24, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@chalasrchalasrchalasr approved these changes

@srozesrozeAwaiting requested review from sroze

@jderussejderusseAwaiting requested review from jderusse

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

[Messenger] Defining transport dynamically

10 participants

@abarkine@carsonbot@diimpp@r6rob@chalasr@nicolas-grekas@tg-mvooges@TCM-dev@fabpot@jderusse

[8]ページ先頭

©2009-2025 Movatter.jp