Chapters
48 Chapters
|
5:05:05
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial is built with Symfony 4.3, but will work well on Symfony 4.4 or 5.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // v1.8.0
"doctrine/doctrine-bundle": "^1.6.10", // 1.11.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.6.3
"intervention/image": "^2.4", // 2.4.2
"league/flysystem-bundle": "^1.0", // 1.1.0
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.1
"sensio/framework-extra-bundle": "^5.3", // v5.3.1
"symfony/console": "4.3.*", // v4.3.2
"symfony/dotenv": "4.3.*", // v4.3.2
"symfony/flex": "^1.9", // v1.21.6
"symfony/framework-bundle": "4.3.*", // v4.3.2
"symfony/messenger": "4.3.*", // v4.3.4
"symfony/property-access": "4.3.*", // v4.3.2
"symfony/property-info": "4.3.*", // v4.3.2
"symfony/serializer": "4.3.*", // v4.3.2
"symfony/validator": "4.3.*", // v4.3.2
"symfony/webpack-encore-bundle": "^1.5", // v1.6.2
"symfony/yaml": "4.3.*" // v4.3.2
},
"require-dev": {
"easycorp/easy-log-handler": "^1.0.7", // v1.0.7
"symfony/debug-bundle": "4.3.*", // v4.3.2
"symfony/maker-bundle": "^1.0", // v1.12.0
"symfony/monolog-bundle": "^3.0", // v3.4.0
"symfony/stopwatch": "4.3.*", // v4.3.2
"symfony/twig-bundle": "4.3.*", // v4.3.2
"symfony/var-dumper": "4.3.*", // v4.3.2
"symfony/web-profiler-bundle": "4.3.*" // v4.3.2
}
}
10 Comments
Hi SymfonyCasts.
First i want to thank you for all your work, i have respect for all the energy you put into these videos.
I've learned about messenger a week ago. I think it's great.
Right now I want to start using messenger with an Api Platform application (
https://api-platform.com/docs/core/messenger/).I do this together with doctrine.
What i want to know is this:
When a client calls an url on my api that generates lots of documents and this generating is handled with messenger, is there a way to let the client know that the documents are ready?
Right now i have a listener that listens for the messenger event 'onMessageHandled'. I was thinking i could do something there. Am i on the right track?
And what is best practise, put the documents at a certain location?
Thank you very much in advance and keep up the good work !!!
With kind regards,
Annemieke
Hey @Annemieke-B ,
First of all, thanks for the kind words about our courses!
Yeah, I think you're on the right track. Listening for the
onMessageHandledevent should be a solid approach for notifying the client when document generation is complete.When docs are handled - you can update the status of it in the DB so that the system knows docs were processed. There're a few techniques that should help you to notify your clients:
You can store documents in a secure location, such as a cloud storage bucket or a file server, and provide the client with a URL to access or download the documents. If it's a temporary files - you can run some CRON job that will clean up old docs to save some hdd space. Also, to avoid files leaking you can sign download URLs, IIRC AWS cloud bucket allow this for example. Then even if the user will reshare that URL with other users - it will be invalidated shortly.
I hope this helps and good luck with it!
Cheers!
Thank you very much for the quick response @Victor !
I've looked at both ways, the polling and the websockets. Both have some disadvantages.
The reason the api client wants to receive these documents is so they can create an email including these documents and send this to a 'customer'.
I have suggested to project leader to create this mail ourselves. I think this will work must faster and safer.
Thanks for your help. And please let me know what you think of my solution if you have the time.
With kind regards,
Annemieke
Hey Annemieke,
Indeed, both ways will have pros and cons, so it's mostly about choosing the best option for your specific needs.
Actually, your idea sounds like a good 3rd option. I don't know your specific project of course, but it can be automated this way - it sounds like a double-win.
Cheers!
Hi Ryan, is it possible to delay 5 seconds between handling each message?
Hey @Core!
Hmm, I'm not sure! You can add a
DelayStamp, but I don't think that's what you're referring to. Why do you want to delay exactly? Anyways, one way to do this would be to add a listener to theWorkerMessageHandledEventevent and, inside, literallysleep(5). That might sound a bit crazy, but that's actually what the worker (i.e.messenger:consume) already does between messages: it does ausleep(1000000)(equivalent tosleep(1)) after not finding any new messages before checking again - https://github.com/symfony/symfony/blob/69f46f231b16be1bce1e2ecfa7f9a1fb192cda22/src/Symfony/Component/Messenger/Worker.php#L134Cheers!
Is it possible to set custom "queue name" with parameter on
$messageBus->dispatch($message);
For example, "competition_41".
I need progress bar 0-100% for each "competitions messages".
Hey Dmitriy!
I don't think this is easily possible. The problem is that... queue systems aren't meant to be used this way. For AMQP, for example, you're supposed to send to an "exchange"... which then delivers to one or more queues based on routing rules. It seems like it should be possible, but you're not "supposed to" think about "sending a message directly to a queue".
If you're using AMQP, this is still possible - but you'd need to set some things up manually. It would look something like:
A) Create the 100 queues that you need in AMQP.
B) Set up some custom routing in AMQP so that different routing keys (e.g. competition_41) send to different queues (e.g. competition_41).
C) In Messenger, attach a custom AmqpStamp to the message with whatever routing key you want.
If you're using the Doctrine transport, I don't think making the queue dynamic is at all possible. I don't fully understand what you're trying to accomplish, but I may try to do it a different way.
Cheers!
Hello,
As a side note in your text, you wrote that redis transport delay is not supported in sf4.3, but may be added in future --> I think it's ok now since 4.4 ? https://github.com/symfony/... ? If so, we can update the text :) cheers !
Hey Julien R.!
Excellent idea - we'll add a note!
Cheers!
"Houston: no signs of life"
Start the conversation!