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
[shopsys] added core for dispatch/consume system #2907
Conversation
7c926aa
to
d68fc0c
Compare
61cc905
to
ef2ebac
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.
Hi, nice job, I have added just a few notes
packages/framework/src/Component/Messenger/ExampleDispatcher.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/Messenger/DeferredEnvelope/DeferEnvelopeMiddleware.php
Outdated
Show resolved
Hide resolved
.../framework/src/Component/Messenger/DeferredEnvelope/DispatchCollectedEnvelopesSubscriber.php
Outdated
Show resolved
Hide resolved
.../framework/src/Component/Messenger/DeferredEnvelope/DispatchCollectedEnvelopesSubscriber.php
Outdated
Show resolved
Hide resolved
.../framework/src/Component/Messenger/DeferredEnvelope/DispatchCollectedEnvelopesSubscriber.php
Outdated
Show resolved
Hide resolved
packages/product-feed-heureka/src/Model/FeedItem/HeurekaProductDataBatchLoader.php
Show resolved
Hide resolved
ef2ebac
to
91c63ad
Compare
feedback from testing:
✔️ When there is an error that causes the closing of the entity manager, the message processing is stopped immediately, and the message is not re-enqueued. ✔️ the messages are actually dispatched on kernel response, on console terminate, and after another message is processed - so it is ensured the data are already committed in the database when handling the message. ✔️ the internal service cache is cleared after a message is processed. One thing that surprised me - when the message processing fails on a regular exception, it is then enqueued 3 more times - I believe that is ok. For a reason, I was expecting 3 attempts in total but actually, there are 4 attempts to process the message. |
Thanks for testing. I have improved this scenario :)
🤔 hmmm... I'm not sure. According to this it seems like it should be retried 3 times (that makes the 4 attempts in general) but then this talks about three failings... well, all in all, we can adjust the behavior with the max_retries configuration |
Awesome, thank you, I have re-tested it, works like a charm, so I am moving the task further in the process 😉 |
- "at the end": - on kernel response (i.e. after a DB transaction is committed) if there is a request - on console terminate if in console - on message handled if in consumer - custom DeferEnvelopeMiddleware stores all dispatched messages and stops propagation to the other middlewares - the middleware is actually called twice, however, the storing is done only when the message is dispatched, not at its receival - see https://symfony.com/doc/current/messenger.html#middleware - DispatchCollectedEnvelopesSubscriber takes all the stored messages and redispatch them for further processing - custom stamp DeferredEnvelopeStamp ensures that this time these messages will be sent to the queue
- on services implementing ResetInterface, the reset() method is called automatically after each message - see https://symfony.com/doc/current/messenger.html#stateless-worker
a22b6d9
to
1b4c11a
Compare
What is done:
AbstractMessageDispatcher
should be used as a base class for all future dispatchers. Provides the necessary dependencies and is configured automaticallyResetInterface
, so they are automatically cleared on each message (prevent stale in-memory data)🌐 Live Preview: