Chapters
57 Chapters
|
6:19:46
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
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!
47.
Mercure: Pushing Stream Updates Async
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.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1", // 1.11.99.1
"doctrine/annotations": "^1.0", // 1.13.1
"doctrine/doctrine-bundle": "^2.2", // 2.3.2
"doctrine/orm": "^2.8", // 2.9.1
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"sensio/framework-extra-bundle": "^6.1", // v6.1.4
"symfony/asset": "5.3.*", // v5.3.0-RC1
"symfony/console": "5.3.*", // v5.3.0-RC1
"symfony/dotenv": "5.3.*", // v5.3.0-RC1
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/form": "5.3.*", // v5.3.0-RC1
"symfony/framework-bundle": "5.3.*", // v5.3.0-RC1
"symfony/property-access": "5.3.*", // v5.3.0-RC1
"symfony/property-info": "5.3.*", // v5.3.0-RC1
"symfony/proxy-manager-bridge": "5.3.*", // v5.3.0-RC1
"symfony/runtime": "5.3.*", // v5.3.0-RC1
"symfony/security-bundle": "5.3.*", // v5.3.0-RC1
"symfony/serializer": "5.3.*", // v5.3.0-RC1
"symfony/twig-bundle": "5.3.*", // v5.3.0-RC1
"symfony/ux-chartjs": "^1.1", // v1.3.0
"symfony/ux-turbo": "^1.3", // v1.3.0
"symfony/ux-turbo-mercure": "^1.3", // v1.3.0
"symfony/validator": "5.3.*", // v5.3.0-RC1
"symfony/webpack-encore-bundle": "^1.9", // v1.11.2
"symfony/yaml": "5.3.*", // v5.3.0-RC1
"twig/extra-bundle": "^2.12|^3.0", // v3.3.1
"twig/intl-extra": "^3.2", // v3.3.0
"twig/string-extra": "^3.3", // v3.3.1
"twig/twig": "^2.12|^3.0" // v3.3.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.0
"symfony/debug-bundle": "^5.2", // v5.3.0-RC1
"symfony/maker-bundle": "^1.27", // v1.31.1
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/stopwatch": "^5.2", // v5.3.0-RC1
"symfony/var-dumper": "^5.2", // v5.3.0-RC1
"symfony/web-profiler-bundle": "^5.2", // v5.3.0-RC1
"zenstruck/foundry": "^1.10" // v1.10.0
}
}
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@babel/preset-react": "^7.0.0", // 7.13.13
"@fortawesome/fontawesome-free": "^5.15.3", // 5.15.3
"@hotwired/turbo": "^7.0.0-beta.5", // 1.2.6
"@popperjs/core": "^2.9.1", // 2.9.2
"@symfony/stimulus-bridge": "^2.0.0", // 2.1.0
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets", // 1.1.0
"@symfony/ux-turbo": "file:vendor/symfony/ux-turbo/Resources/assets", // 0.1.0
"@symfony/ux-turbo-mercure": "file:vendor/symfony/ux-turbo-mercure/Resources/assets", // 0.1.0
"@symfony/webpack-encore": "^1.0.0", // 1.3.0
"bootstrap": "^5.0.0-beta2", // 5.0.1
"chart.js": "^2.9.4",
"core-js": "^3.0.0", // 3.13.0
"jquery": "^3.6.0", // 3.6.0
"react": "^17.0.1", // 17.0.2
"react-dom": "^17.0.1", // 17.0.2
"regenerator-runtime": "^0.13.2", // 0.13.7
"stimulus": "^2.0.0", // 2.0.0
"stimulus-autocomplete": "https://github.com/weaverryan/stimulus-autocomplete#toggle-event-always-dist", // 2.0.0
"stimulus-use": "^0.24.0-1", // 0.24.0-2
"sweetalert2": "^11.0.8", // 11.0.12
"webpack-bundle-analyzer": "^4.4.0", // 4.4.2
"webpack-notifier": "^1.6.0" // 1.13.0
}
}
14 Comments
As symfony/ux-turbo-mercure has been abandoned (files are located in symfony/ux-turbo), you now should run
composer req symfony/mercure-bundleinstead.Also, set
enabledtotruein assets/controllers.json for the mercure-turbo-stream config.I just wanted to add to jmsche's post. I'm running this tutorial with Symfony 5.3 and PHP 8.1 (as of 5/24/2023).
When attempting to run
composer require symfony/mercure-bundleI get the following error:To resolve this, I first had to update symfony/flex with
composer update symfony/flex --no-plugins --no-scripts(per this post) and I also had to downgrade PHP to 7.4 (from 8.1).Then mercure installed fine. Hope that helps someone!
Hey! Is there really a Mercury tutorial planned? That would be great ! If yes, for when could we have access to it?
Do you plan to do a Mercury training again combining it with Turbo, or this time, with a traditional Symfony project not using Turbo?
Hey Kiuega,
Thank you for your interest in SymfonyCasts tutorials. Yes, we do plan a tutorial about Turbo... and it might happen this year. About Mercury - I'm not sure, but most probably it might be covered / partially covered in that Turbo tutorial. Though, we don't have specific plans for this yet, and we have some other pending tutorials that will be released first. In short, we would love to release a tutorial about Mercury and Turbo, but I can't tell you when it might be released yet.
Thank you for your patience!
Cheers!
Hi Victor,
Any update on this? Would love to have a definitive guide on how Async / Websockets is done in Symfony.
Regards,
XXX
Hey Aries,
Turbo tutorial is released: https://symfonycasts.com/screencast/turbo - and we do talk about Mercure there :) Enjoy! Also, feel free to use our advanced search to find more related content in other tutorials, e.g. this
Cheers!
Hello guys,
In the Mercure's doc there are a feature named Discover which is not very clear for me of its purpose. So if I understand correctly, the client will make a request to a controller Discover, it will add the Link with Mercure public hub URL in the Header so the client code could extract to get that URL to subscribe. From the docs :
But with twig we have a function for example
{{ mercure("mytopic")|escape('js') }}to get the full link of mercure URL and topic. Or, why in controller we don't get the hub URL and then just return it. Why we want to make another request to DiscoverController just to get that Hub URL for the client?Hey Dang,
Most probably you don't need it if you are not sure why it might be useful for you :) The most preferable way - use that
mercure()Twig function if it fits your needs well. What about the discovery feature - I didn't use it on my own, so difficult to say. It might be useful for third-party clients, e.g. who are using your Mercure Hub from a different website, or maybe even via API requests, as usually those headers are mostly used in API.In other words, I think it might be useful for all your clients who want to know your Mercure hub URL outside of your project. But in your project, it's more convenient to use that Twig function that would help you to build the correct URL to the specific resources for you.
I hope it makes sense to you :)
Cheers!
Hello,
I do not think you should be advertising for Mercure's "managed service".
I tried it. There are no free trials or demonstrations of how the managed service works so you're basically throwing $30 into a black hole and hoping something cool pops back out.
I get in, and the user interface is extremely oversimplified with absolutely no help or guide on how to set it up. All of the documentation on the site have to do with setting up a local demo hub on your own server, and I could find nothing on actually using the managed service.
I tried my best, but kept getting ssl and authorization errors and there's no way to try and fix it, you don't have access to the Caddyfile.
I ended up going through the grueling process of setting up a mercure hub on an aws server myself and got it to work,
but that money is gone.
Hi Nick,
I am very sad to hear that you had a bad experience with Mercure.
The interface is intentionally simple, to use the managed version you just need to set up a secure JWT key. Optionally, you can set a custom domain (for CORS and performance) and use the user interface to set the options available on the free version as well. Everything works exactly as with the free version, and you have access to the same options without having to deal with a Caddyfile (the managed version uses a custom build on top of the free version under the hood).
If you (or anyone else in the same situation) try our service again and have problems with the configuration, support (contact@mercure.rocks) will be happy to help. Also, feel free to contact us at the same address for a refund.
I hope that you'll give us another try in the future.
Hi Nick!
Oh man, that is a terrible experience - but I really appreciate the honest feedback. I'm going to pass this along to someone I know in the Mercure space - hopefully it can be useful to them. And I'd like to get some answers from them also to make sure it's a smoother process. The idea of mentioning it in the tutorial is so that you could have an EASIER time using Mercure - but you had the opposite :/. Btw, I'd also message the Mercure people and ask for a refund - you can't get your time back, but they should refund your money.
Cheers!
Hi Ryan,
I'm working on getting connection between Mercure and React Native Mobile App and I am almost disappointed on finding a way how it works!
The Mercure debugging tools works on my local Host and I can publish data on client side (i have tested this with a simple Symfony page) and when it comes to React Native I use Server Sent Event(SSE) to listen to updates from Back-end! But I'm not receiving anything!
Any help or tip will be appreciated!
the library i use is the following <React Native EventSource>
https://bestofreactjs.com/repo/binaryminds-react-native-sse
my mercure hub url: <http://localhost:3000/.well-known/mercure>
my mercure publish url <https://myIP:3000/notifications>
here is my react native code
Hey Roozbeh S.!
Hmm, unfortunately, I'm also not sure what could be the problem or how you could debug better :/. Are you able to go directly to http://myIP:3000/.well-known/mercure?topic=https%3A%2F%2FmyIP%3A3000%2Fnotifications in your browser and see the updates being loaded there? You may have already done this - I wasn't totally sure you have yet. If that DOES work, then you know things are publishing correctly and I would look closer at the JS code... though your code looks pretty similar to the core Mercure + Turbo code (it's not exactly the same use-case, but the EventSource stuff is the same - https://github.com/symfony/... )
Sorry I can't be more help!
Cheers!
Hi Ryan,
on the browser (Mercure Debugging Tools) works perfectly!
Thank you.
"Houston: no signs of life"
Start the conversation!