Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Messenger] add a transport that processes messages on kernel.terminate#28746
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
gonzalovilaseca commentedOct 5, 2018
(Deprecation label should be removed BTW) |
src/Symfony/Component/Messenger/Handler/KernelTerminationHandler.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
sroze commentedOct 6, 2018
I think the approach of having a decorated handler might not be the best. What aboutusing a transport for this? |
gonzalovilaseca commentedOct 11, 2018
@sroze Not sure if I got it right....is this the right approach? If it is, I'll create tests, documentation etc. |
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransport.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransport.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransport.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransport.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransport.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ogizanagi commentedOct 11, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Just for the sake of completeness, here is the whole workflow to me:
I'm just not sure about 4. Perhaps it should be configurable at the transport level as an option. |
| ; | ||
| if ('symfony://kernel.terminate' ===$transport) { | ||
| $transportDefinition->addTag('kernel.event_listener',array('event' => KernelEvents::TERMINATE)); |
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.
Can't you take the event from what is aftersymfony:// instead of hardcoding it?
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.
Does it make sense if we're only going to listen to that event?
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.
See comments after#28646 (comment).
I'm not convinced another use-case should be provided out-of-the-box by the Framework bundle.
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransport.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Transport/KernelTerminate/KernelTerminateTransportFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedOct 24, 2018
See#28646 (comment) for more thoughts on this. |
gonzalovilaseca commentedOct 25, 2018
I've updated the PR as per the comments (hope I understood all comments correctly...).
|
gonzalovilaseca commentedOct 25, 2018
BTW does anyone have a sandbox project I could use to test this functionality? |
gonzalovilaseca commentedOct 28, 2018
@sroze@nicolas-grekas@ogizanagi Have updated the PR with suggestions given, it's not ready to review yet as it's not complete, but would like some feedback to check if I'm in the right direction before doing the final work. |
ogizanagi commentedOct 28, 2018
@gonzalovilaseca : Sorry for the lack of answer.
I think the factory should be aware of all the available buses, by injecting a service locator. Then, a transport option should allow the factory to select the right bus by its key. |
gonzalovilaseca commentedOct 28, 2018
Can you check what I've done in |
ogizanagi commentedOct 28, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
You may have more than one of such transport. For instance one per bus. The factory would be used to create each of these then (so it needs to know every buses). |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
gonzalovilaseca commentedOct 29, 2018
updated! |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
gonzalovilaseca commentedOct 30, 2018
@sroze@nicolas-grekas@ogizanagi Are we happy with this as it is, so I can start writing tests? |
ogizanagi left a comment
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.
Looks good (to me) yes :)
...Symfony/Component/Messenger/Transport/KernelTerminate/SymfonyKernelEventTransportFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
gonzalovilaseca commentedOct 30, 2018
Updated! |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ogizanagi commentedOct 31, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@gonzalovilaseca: I hope you won't mind me, but I've rebased and pushed some changes to your branch hopefully fixing@sroze's review and some other tweaks I've spotted during this operation :) |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Transport/KernelTerminateTransportFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| ->addTag('messenger.receiver',array('alias' =>$name)) | ||
| ; | ||
| if (0 ===strpos($transport['dsn'],'symfony://kernel.terminate')) { |
ogizanagiOct 31, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Hmm. I just realized this won't work with env vars.
As I don't see any use-cases for it, it may be fine, but we need extra pov.
If we want to support it, the kernel terminate transport factory will need the event dispatcher and add listeners itself (still, that would be a better implementation and give the factory even more sense?).
(Note the same goes for theamqp:// check above, but it's only about a hint for the developper)
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
gonzalovilaseca commentedNov 9, 2018
@ogizanagi@sroze I've updated the PR with tests |
ogizanagi commentedNov 10, 2018
@gonzalovilaseca : Great! :) But I think we need to treat#28746 (comment). Consistency is the key, this transport dsn should work as an env var as any other. Regarding#29097 (comment), I also think we should extract the re-dispatching logic out of the |
| */ | ||
| publicfunctionstop():void | ||
| { | ||
| $this->envelopes =array(); |
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.
Instead of emptying, we may just use a$stopped flag used in receive to skip handling as in
| if (!$this->stopped) { |
gonzalovilaseca commentedNov 10, 2018
Can an event be registered at runtime? (I thought that wasnt possible as the container is already compiled) |
ogizanagi commentedNov 10, 2018
Sure. You'll need to inject the |
gonzalovilaseca commentedNov 10, 2018
Ok cool, will do that then. |
gonzalovilaseca commentedDec 13, 2018
@ogizanagi updated following suggestions |
| publicfunctionflush():void | ||
| { | ||
| $this->receive(function (Envelope$envelope) { | ||
| if (null ===$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.
$envelope can not benull here, because of the type hint.
| $transport =newMemoryTransport($this->busLocator->get($busId)); | ||
| $this->eventDispatcher->addListener(KernelEvents::TERMINATE,array($transport,'flush')); | ||
| $this->eventDispatcher->addListener(KernelEvents::EXCEPTION,array($transport,'stop')); |
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.
Do we also have to add listeners to the corresponding console events?Like in swiftmailer-bundle for the memory spool?
gharlan commentedMar 14, 2019
Any chance to get this merged into 4.3? (feature freeze is in two weeks) |
gonzalovilaseca commentedMar 14, 2019
It's just waiting for review.. |
sroze commentedApr 6, 2019
Thank you very much for your efforts on this pull-request@gonzalovilaseca. Now that we have other transports (Doctrine especially) I think that the risks associated with such transport are too high:as mentioned by @fabpot ealier, running things on Let's close this so we push everybody to use more reliable solutions 🚀 |
nicolas-grekas commentedApr 6, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sorry for making you work on this, but even if it wasn't merged, it helped a lot moving things forward! So thank you! |
Uh oh!
There was an error while loading.Please reload this page.
I'm not sure if this is what Nicolas was asking for in this issue:#28646 (comment)
If it is, there are some questions that need general consensus: