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
}
}
4 Comments
Hi! I'm working with the Symfony framework, and I'm using Messenger. I want to know if there is a way to ignore some messages when I'm using middlewares without finish with a error or exception or exit. For example, if I have already consumed a particular message and I want to ignore it.
Hi John Esteban!
Hmm. I've never done this before, but yes, I think this is definitely doable. One of the things you need to have in any middleware is this line:
Example: https://github.com/symfony/symfony/blob/8e8207bb72d7f2cb8be355994ad2fcfa97c00f74/src/Symfony/Component/Messenger/Middleware/AddBusNameStampMiddleware.php#L37
This is literally what calls the NEXT item in the middleware. If you changed this, instead to:
Then I'm pretty sure that the rest of the middleware change would not execute. So as long as your middleware is put before the "handle message" middleware (and this will happen automatically), then this should do the trick.
Let me know if you're successful.
Cheers!
I'm trying to figure out how to using the Symfony Messenger component in a non-Symfony application. I've got it working fine in Symfony to send AMQP messages to RabbitMQ, but I need to send AMQP messages from a legacy PHP application. Basically, I need to figure out how to configure my own SendMessageMiddleware to work the same way as Symfony. The current documentation at https://symfony.com/doc/cur... is not very helpful. All it says is "...with Symfony’s FrameworkBundle, the following middleware are configured for you: SendMessageMiddleware...".
I need an example of how to do it myself without the Symfony magic.
Hey Jeff Groves !
Ah yes :). This is (as you correctly noticed) not the "first class citizen use case" in the docs - it's tricky, we have to write the docs primarily for the main audience. That, indeed, makes the "standalone component" usage trickier!
So let's talk about
SendMessageMiddleware. This class itself is quite simple - the tricky part is theSendersLocatorInterfaceconstructor argument, which normally Symfony handles creating for you. This is the concrete class that Symfony uses: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.phpBut, let's stop right there :). The full Symfony Framework Messenger is super feature rich and complex. And you may not need to hook up the same level of complexity and features in your legacy app. The simplest thing to do would be to create your own implementation of
SendersLocatorInterface- it's a beautifully simple interface: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Messenger/Transport/Sender/SendersLocatorInterface.phpInside,
getSenders(), you could call$envelop->getMessage()and, if you want, just have a big map of which message class should go to which "SenderInterface". Or... maybe you only have one Sender/Transport. In that case, you could literally just return it:Let me know if that makes sense - or if there is something else tripping you up in this process :).
Cheers!
"Houston: no signs of life"
Start the conversation!