-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Add TransportNamesStamp
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Messenger] Add TransportNamesStamp
to change the transport while dispatching a message
#39306
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
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! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
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.
Thank you for this contribution.
What if people want keeping the original senders?.
I wonder if we couldn't use something similar to the BusNameStamp
:
- use a middleware that initialize the envelope with a
SenderNamesStamp
- send the envelope to the senders contained in the last
SenderNamesStamp
src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php
Outdated
Show resolved
Hide resolved
Wouldn't it add an overhead? In current way, Envelope will not include OverrideStamp if not necessary. What do you think? |
On naming note, public stamp name shouldn't be derived from this moment internal implementation, so something like As library user, who is not privy to all the internals, first naming choice would be |
@diimpp , thanks for your input, I will change the name, what do you think about the implementation? |
@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. |
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 specify Then they will want to keep their original transports list and just add another one, e.g. 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. |
Good point. It will make SendersLocator class a bit complex but I guess it will add a great value to the Stamp. |
@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. |
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. |
@asilelik Thank you for the PR. Please go ahead with the missing tests, this looks good to me. |
@chalasr I've added the test. Apart from |
Yes, the failing test is unrelated. |
@chalasr what is the preferred way for getting rid of merge commit? Can I force push or is there any other suggestion? |
I missed that Jérémy's comment, thanks.
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. |
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. |
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 name OverrideSendersStamp) 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? |
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.
I've rebased this PR and made some naming changes to finish it.
adfbd37
to
1a5f229
Compare
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 ^_^ |
1a5f229
to
239ea41
Compare
@tg-mvooges That's the case. See https://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? |
SenderNamesStamp
to change the transport while dispatching a message
Looks perfect to me and more consistent with other stamp names. |
239ea41
to
bffb292
Compare
Even if Sender is the right word, I think you're right that using Transport is easier to understand. Updated accordingly. |
bffb292
to
d9f1254
Compare
SenderNamesStamp
to change the transport while dispatching a messageTransportNamesStamp
to change the transport while dispatching a message
d9f1254
to
c47334e
Compare
c47334e
to
f526af0
Compare
Thank you @asilelik. |
…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
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! |
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.