-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] dispatch event when a message is retried #36152
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
src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php
Show resolved
Hide resolved
Can you please provide a use case for this? |
@chalasr we're aggregating some metadata for each message ( But if a message is sent by another system (eg: in a micro-services architecture), we cannot use |
@nikophil Works for me, thanks. Can you add a CHANGELOG entry for this? |
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.
-1 on this feature as people can just use the WorkerMessageFailedEvent with a priority that comes after the SendFailedMessageForRetryListener
@@ -29,6 +29,11 @@ public function getEnvelope(): Envelope | |||
return $this->envelope; | |||
} | |||
|
|||
public function setEnvelope(Envelope $envelope) | |||
{ | |||
$this->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.
making the envelope mutable means, all the dispatching of events would need to be changed to refetch the potentially modified envelope, e.g. in
symfony/src/Symfony/Component/Messenger/Worker.php
Lines 105 to 113 in 7ab51f3
$event = new WorkerMessageReceivedEvent($envelope, $transportName); | |
$this->dispatchEvent($event); | |
if (!$event->shouldHandle()) { | |
return; | |
} | |
try { | |
$envelope = $this->bus->dispatch($envelope->with(new ReceivedStamp($transportName), new ConsumedByWorkerStamp())); |
just adding a setter does not do anything by itself. -1 on doing this.
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.
Yes, this part is missing. But do you see it as a huge problem to (effectively) add $envelope = $event->getEnvelope()
? I made the events immutable originally because I feel that it's always better to be conservative until we have a use-case. But this PR now does have a use-case.
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.
sorry i missed that...
in case this PR is accepted, i've fixed that and refetched envelope from mutable events.
i've added two new tests cases which check that events mutability is handled
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.
Did we need to add this in the abstract class? This will affect (on master currently) 3 classes. Maybe we need hook points in all of them? But in this PR, we only need a hook point in one of them.
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.
ok, i'll do that, it will be less error prone this way
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.
done :)
I'm still supportive of this feature, but we would need @Tobion to reconsider his vote :) |
@Tobion Can you have another look at this PR? |
src/Symfony/Component/Messenger/Event/WorkerMessageReceivedEvent.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Event/WorkerMessageRetriedEvent.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php
Outdated
Show resolved
Hide resolved
@nikophil Still willing to finish this PR? |
src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml
Outdated
Show resolved
Hide resolved
Hi, yes sorry, i'll do that shortly |
src/Symfony/Component/Messenger/Event/WorkerMessageReceivedEvent.php
Outdated
Show resolved
Hide resolved
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.
This is ready - it duplicates some logic from #32904, as both PR's needed the same extension point.
Thank you @nikophil. |
Hello,
i'm working on a bundle which helps to monitor messenger queues (add some stats for queues/transports + ability to manage failed messages from the browser)
https://github.com/SymfonyCasts/messenger-monitor-bundle/
and we're missing some hooks in the messaging system:
WorkerMessageRetriedEvent
inSendFailedMessageForRetryListener::onMessageFailed()
)AbstractWorkerMessageEvent::setEnvelope()
)if needed i can provide some precise use cases.
thanks.