-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Adding a middleware to allow you to "hook into" the stamping process #30646
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
Conversation
feb0c77
to
aa0e880
Compare
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.
Nice contribution, thanks Ryan 👌🏻
/** | ||
* Apply new stamps and return the new envelope. | ||
*/ | ||
public function stampEnvelope(Envelope $envelope): Envelope; |
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 would propose stamp(...) because stamp and envelope are already mentioned in the interface name
Closing in favor of #30650 - please check that one out! |
…d (weaverryan) This PR was merged into the 4.3-dev branch. Discussion ---------- Dispatching two events when a message is sent & handled | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | TODO Alternative to #30646. This uses a more generic system, so you could do anything when a message is sent. The main use-case is when a message is dispatched by a 3rd party. I didn't try to add *exhaustive* events everywhere: I added an event for a very specific use-case: When a message is dispatched by a 3rd party, being able to add stamps (e.g. `DelayStamp` or a future `AmqpRoutingKeyStamp` before the message is sent. Example: ```php class MailerMessageSendToTransportEventSubscriber implements EventSubscriberInterface { public function onSendMessage(SendMessageToTransportsEvent $event) { $envelope = $event->getEnvelope(); if (!$envelope->getMessage() instanceof SomeMailerMessage) { return; } $event->setEnvelope($envelope->with(new AmpqRoutingKeyStamp('mailer-route'))); } public static function getSubscribedEvents() { return [SendMessageToTransportsEvent::class => 'onSendMessage']; } } ``` Along with #30557, we will now have the following events, regarding async messages: * Event when a message is sent to transports (this PR) * Event when a message is received from transport, but before handling it * Event when a message is received from transport and after handling it Commits ------- a7ad1b4 Dispatching two events when a message is sent & handled
When a 3rd party dispatches a message, the user may need to apply some custom stamps to that message - especially stamps that configure how that message is handled by the transport. We already have one simple example of this from #30557 - the
DelayStamp
. This would allow the user to very easily (without needing to create a middleware and register it) add this stamp to a 3rd party message, or future stamps (e.g. stamps for transport/queue priority).