Laravel Microservices Full Course | Event Driven Architecture with RabbitMQ

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this tutorial we will build a simple microservices example with laravel the front end of this app will be built on angular react and view so you can pick your favorite there as for the back end we have two laravel apps admin and main where they have their own database with different data they communicate with each other through rabbitmq events and in one case the main app will internally call the admin up to retrieve some data both laravel apps will run through docker so we will learn some docker commands along the way too before i show you how the app looks like i would like to share this udemy course that i created where it's even more advanced than this course that we are building so this is a 15 hours course and you will learn a lot of things like how to break a monolith no microservices upload packages to composer so you can use your own packages also upload packages to npm you will pay with stripe etc etc so i will put a link in the description and you can check it if you like this course on youtube so this is the app that we will build it's a simple app where this is a admin and this is the main app in the main app we can like the products and in the admin app we can create the products it is very simple but don't get deceived because it it has two backend apps with different database communicating with rabbitmq which i open it on my right side so let's see an example for example i will like this product here and when i like the product you will see an event happening in rabbidmq right now so the event has been triggered here and we have one ready event and now is zero so it means it was consumed so if we see here let's refresh the admin we can see that we got another like here so in essence it's really simple but this like has more functionality to it since it will internally call also the admin to get a random user and if we happen to like with the same user it will throw an error we can also create a new product so let's create a product and i will add a sample image we will see that the rabbitmq will trigger another event so this is a product that we created another head event has been fired and when it's consumed here we will see the product here so it seems that the product is on the admin up on the main app so we got the product so we will see how this app will work by building them so let's start creating the apps now let's start a new laravel project and also connected with docker to install docker go to docker desktop to docker.com products dr docker desktop and download the right version for you once it's completed you will have an icon here for the docker desktop now to install laravel the current version of laravel is 8 and you can use either this command or i will use this command since i already have the installer so i'll create the first project laravel new admin let's wait till uh is completed now it's completed and let's open the folder with our id so i'll already open it so before making any changes i will install this package laravel ide helper because it's really helpful while we are developing since it will add more helpers to our intellisense so let's install this package now that is completed run php artisan id generate so it will generate a file here so this file will help our intellisense now before making any changes we will add the docker files so i will add docker file here and in this docker file we need to specify the from in the beginning so where this app is coming so from ubuntu usually but i will keep it simple and this is a php app and the version of php is 7.4 so this is the container that we will start with 7.4 built on it now along with php we need more packages to be installed so i'll paste it directly here so this looks a bit scary but i will paste this commands in the description so you can use it the same this last command is to install composer so we can immediately run composer in this app now that we installed php with all the packages that are needed we can focus on our app so we have to specify the working directory i'll just use up and let's copy dot dot here so the first dot is this up so this all hub and this other dot is the working directory so i will copy all the files here to uh the folder up in the docker container and once i copied all the files i need to run composer installed so run composer install so once this composer install has run our app is ready to be executed so we have to run another command here which is php artisan serve and i will specify the host which is 0.0.0.0 so it's localhost basically when we do php artisan serve it usually exposes support 8000 so i will write expose port 8000 so this container now that we built will run through port 8000 now we completed the docker file we need to add another docker compose file docker compose dot yaml so to run the docker compose file we have to add first the version so the version for the docker compose is 3.8 latest one and we have to add the services so the first service is our admin app so admin and here we want to connect this docker compose file with a docker file that we just created so we have to specify a build the context is this folder and the docker file is this docker file that we just created so with this command we specif we told docker compost that use this docker file basically now we have is basically completed but we still we need one more thing which is ports so this sports is which part we want to show it to localhost so we already exposed port 8000 but this is a docker container port but not our local host so the port here will be eight thousand eight thousand and this eight thousand is a port inside the docker container and this is the port that we want to show to our local host so with this our app is running but we still need the database so we have to add mysql here so let admin db which i will download the image from mysql and i have to specify here the version which is 5.7.22 so now we got the mysql but still we have to specify the passwords in the database so we have to add the environment here we need the mysql database which is admin mysql user which is whatever i will put it root mysql root password this is root again and mysql password which is also root so basically the difference between mysql the root password and mysql password is that well this one is for the user so i can move it up so this is for the user root as a password root and for this other password is for the admin that owns the mysql so you don't have to worry about it so you have to just use these credentials so we are not done yet here so we had to add the volumes the volumes is basically uh we have to map our files here locally to mysql files so we can uh move files back and forth from the docker container to our app or to our app to the docker container so i will map the folder storage db data to var lib mysql so inside the storage folder now you will see db data and we need this because mysql stores some information will store to this folder and it doesn't work if we don't do this volume and the last change is the ports also here and the default port for mysql is [Music] 3306 which is this is the port inside the docker container and we have to map it to outside so put 33060 i put a different port here because it will conflict with my mysql installation and this way it doesn't conflict it so the last change is that this admin app will use this admin db and to tell this service to use this other service we have to add depends on admin db so this service is dependent on this other service now let's add these changes to our emv file now the db host is admin db the database is admin and the password is root so these are the changes that we want a db port is correct so you don't have to worry about this with that being said now let's run docker compose up and this will build our docker files so we have an error so i already used this port i don't know which app is using this port but i will use another number i will put three here so this is my new port let's build again so we can see that is starting and the database is failing i don't know the reason but usually the first time it fails so let's type command ctrl c again and the docker compose up again and this time mysql will work correctly notice in our storage folder now we have db data which are the files from mysql which is importing here so we can see we didn't have this folder before now we can connect to our mysql so we have to put a data source here i'll put docker here host localhost the port was this port the user was root the password was root and the database was admin let's test the connection and the connection is successful so as we can see we successfully connected with docker let's check it also in our browser so let's type here localhost port 8000 and we can see that laravel is installed it means docker is running correctly now let's create our database let's go to the database folder and we have three folders now factories migrations and seeders so we will explore them now first the migrations these are the commands that we create tables there are three default tables uh when we create a laravert project so this is the users table for the moment i will remove all the fields here and the user table will have only one id i will explain later why i did this we just need the id for now part password resets table we don't need this table we can remove it and the failed jobs table we need disable because we will use rabbitmq and this table will catch the failed events now to create another migration we open the terminal and run php artisan make migration i will create another table create products table and now another migration will appear here and laravel will check the name here and it will automatically create a schema called products so for the products we will add a string title here for the product we will add another string for the image of the product and the last thing that we will add is an unsigned integer likes so the amount of likes that these products got i will add also a default value so if you we create a product in the beginning the amount of likes is zero now we have all the tables in this project we are ready to migrate so the command to migrate is php artisan migrate but this failed what is the reason because here i'm in my localhost and to run this migration i have to be inside the docker container so the first thing that we have to do is go inside the docker container so docker compose exec so let's go to the docker compose file we have to specify the name of the container that we have to go so it's admin admin sh now i am inside the docker container so if i run now php artisan migrate we can see that the migrations are successful if we open also the database and refresh here we'll see the tables so now that we run the tables we can see them so seeders are used to fill the table data along with the factories so let's create another factory for the products but first for the user factory we removed all these fields so we don't need any of these fields the user factory will return an empty array now we need to create another factory for the products so let's create the factory php artisan make factory product factory so we created the factory and it should appear here but it won't why is that because we didn't add something in the services here which are the volumes like the volume here like mysql stored data in the container and also in our app we have to do the same here because we created right now the factory inside the docker container but it's not appearing here so let's add a volume and the volume will map this app with slash app this slash app is uh this working directory here so what i'm mapping is a all these files with a slash app directory now we have to restart our docker container and the factory should appear there we can see now that we got the product factory here and we need the product model so we have to create also that so let's run php artisan make model product we will see the model here so it's already there now we can change this to product and this is the product factory let's remove this the product will have a title which in our case is this fact faker text i'll put 30 characters it will have an image this faker image url we don't need to add the likes because the default value of it is zero so we are finished with our factory now we need to use the seeders so let's run php artisan make cedar product seeder we also need to create the user seeder so php artisan make seeder user cedar so they appeared here let's go to the user seeder to run the cidr we have to use the factory that we created so user factory i'll create 20 users and in the end create so this is how we create 20 users let's do the same for the product seeders product factory then create and in the database seeder we can call our all our separate seeders in one place so we will call this call we'll put an array here and we will add our two seeders which is user seeder that class and product seeder that class now that everything is on place run php artisan migrate sorry dbcd so we had a problem so unknown column updated at in the user's seeder so let's go to the user model so we have a bunch of fields here that we have to remove and uh this should not be also notifiable and in order to remove the updated data and create that from the user we have to use this property public timestamps equals to false this reminds that these fields should not be used in this model let's run again the seeder php artisan db seed and we successfully seeded the database now if we open the database let's go to the users we can see the ideas from 1 to 20. it's really simple but you will know why i will use it later and the products we have some products with a title an image and likes which is equal to zero so this is how you create the migration factories and seeders now let's add the controller for the products so to create a controller run php artisan make controller product controller and the controller is located here now we want to create a crat for the product so the first function that we will add here is index and in this function we have to return all the products so it's pretty simple now we need to map this function to a route to do it we have to go to routes api let's remove this route since we don't need it and right here route get the api that we want to call is products and now we have to map the controller so we have to put an array here and the first parameter is the controller itself so product controller that class and the second parameter is the function that we created which is index so i'm already getting some intellisense here so we can remove this part and we can import it directly here so we can use the namespace this is how we create a route for this function now let's test it if it is successful create an http request i will call it http so you can use a postman if you like i used this phpstorms command because it's i can use everything in one ide but you may use postman we want to have a get request to http localhost port 8000 slash api slash products and uh we don't send any parameters so probably we need uh accept application.json just this header and let's run it so we can see these are all the products that we got so the end point works correctly the second endpoint that we want is to show a single product which is show and here we need to specify the id and we return product find id that this function is highlighting it means it probably doesn't exist but it does exist that's why we installed in the beginning this ide helper which generated this php file let's run the command php artisan id models yes this will generate some comments in the product so right now this find is highlighting correctly so if we go to the products now we can see some comments here which are the functions that are not mapped correctly in our ide so i recommend that package now let's go to our api.php and here we will add the product slash id and this will call the show method so this id will map this id here so if we go to our http and now we want the first product we are getting the first product so let's do the same for all the other endpoints but there is an easier way to map all five endpoints so basically all five endpoints are this post which is products here and this is store put which is product slash id here and this is update and the last one is delete and this is destroy so for every crowd function there are five methods one to get all the products one to get a single product one to create a product one to update the product and one to delete the product laravel has already a function to simulate all these five methods which is api resource so we have to create only one api resource for the products and this only needs a class and this will map all the five functions so let's run php artisan route list we'll see that we got all these endpoints but we have only one function here now let's create all the other functions so let's create store here and this accept the request parameter and now we want to create a product so we'll create a product which is product create and inside we will pass the parameters that we want from the request i will get only the title and the image so we will send this two parameters from the request and we will create a product in the end we will return the response with the product and we also need to pass here the response usually is 201 which is a http created but we can use response from symphony component http foundation we cannot directly http created here so we have the status code when the product is created now let's test it go to http change this to post and this is products we have to add also another header which is a content type application json and we have to add the request parameters the first is the title title here and we want also the image image now we can send this post request and we can see that we have an error so add title to fillable property to a low mass assignment so to to fix this problem we have to go to the product model and we have to add here sorry protected guarded and i will put an empty array so this means that all the fields are fillable usually here you put an id so i'll put an id here but we will remove it later because i will show you now let's try it again we can see we created another product and with a title and an image and id is 11. now let's update this product so let's go to the product controller and we will add the update method update here we need the id and the response sorry the request so first we have to get the product which is product find id and then we have to update this product so we have to call update and we have to use the same as this request here so we have to update the title and the image and in the end we will return a response just like this one except now we need http accepted so this is the update method and now let's copy this id 11 and let's change the title to new title and the image to new image let's send a request we got an error so we have a we have to change this to put so let's run it again so this product now has a new title and a new image now let's remove this product the last method here destroyed we need the id here this troy so to destroy a product we have to write product destroy and id here and for the response we have to send a null value here because it's uh we don't have to send anything so response http no content so once we destroy a product we don't return anything and we return response null with no content let's go to our http and now we want to delete this product we don't want to send any parameters here let's send a request and it successfully deleted the product because now we didn't return to anything we just returned 204 no content now if we do a get request to get this product we won't see the product again so response is successful but it doesn't have a product so this is how you create a cloud api crowds with laravel now let's create our main app right laravel new main let's wait till the installation is completed now that the installation is completed let's go to the folder and install the package for our ide helper now that is installed run php artisan id generate so now let's open it with our id i opened here the project with my id and this is the main app and this is the admin app that we just created now here let's copy the docker files and paste them here so the docker file we don't have to change anything here in a docker compose file we have to change the names so this is main this is main db and let's change this main db here and the database should be main also and we have to change the ports now it needs a different port and for the mysql it needs a different port we don't need to change the docker container port we only need to change our localhost port now the docker compose file is correct let's go to our emv file this is main db here and this should be root now everything should be correct run docker compose up so the database will fail the first time so now it failed and we have to run it again and now it won't fail now let's go to the migrations and let's change the migrations we don't need a user table here neither the password resets table we need the created jobs table now let's go inside the docker container php artisan sorry it should be docker compose exec now the name changed so in the docker compose we have to use main main sh so the docker container didn't run let me see the reason so let's run it with build so i don't know the reason why i didn't run in my machine maybe i already run one main app before now it's running and that's open it again now i'm inside the docker container so here i will create a migration is done make migration create products table it is a product should be product so i will delete this file actually i will copy the file from admin so i will copy this file here and paste it here so this is the products table that we want to create but now we have to change something we don't need the likes here we just need the title and the image and for the id here we have to change id to not be auto increment so we have to make it unsigned big integer id and we want it to be primary why did i make this change is because the products will be created in the admin and we will get a rabbitmq event here so we can create a product with the same id because if we make it out of increment we will have inconsistencies now that we created the migration let's run the migration php artisan migrate so we run the migration we check the database so i will add docker here and the port was this port user was root password root and the database was main test connection so we have the products here now let's create also the controller php artisan mig controller product controller and also the model php artisan make model product and let's go now to the product controller and here we'll create the index function that we will return the product all and let's go to our api and here we will add the route api resource not api resource get products product controller here and we need to map the index function so we created everything now what is missing is getting the event from rabbit and q from the other app which will do it in the next tutorial now we want to send events through rabbitmq i suggest to use this service here cloud ampq which also has a free tier which i will be using so it's good for testing so i already have an account i will log in this is my instance and if we go to rabbitmq manager we'll see the rabbit mq dashboard here so to use this we need to install another package laravel q rabbit mq let's install this package to our projects so this is the main app i'll install it here and i will also install it in our admin app we need also to add this rapidmq connection to our queue.php so i'm already in cue.php here and here i will add this code and i will paste it also here now the package is installed and also i added this configuration now let's go to our emv file but first let's copy this part here and let's go to our emv file and we'll paste it here we need all only the constants here so rabbit mq host we need a rabbit mq port which is correct i will put it that number the guest the password and the vhost so let's copy this part paste it to the env file here also and let's get the values from our rabbitmq management so if we go here we can see this is a host i will copy the host here this is user mv host and i need to paste a password so this is my password don't use my password you can use your free tier i will copy it and paste it here also and the last change is we want to change this q connection here to rabbit mq and let's do it the same for the main app with these changes we are ready to test if our app works so first let's restart our docker containers and you restart the other one too and in the admin app we will send an event that our main app will get the response so let's create a command make command fire event i got the reason there is this x here which i added basically so let's create it again make command fire event so the command is already created so i'll name it just fire here and i will remove all this code and here we want to fire the event so to fire an event we first have to create a job php artisan make job test job so let's create the same job in the other app so we'll create here php artisan make job test job and here we will dispatch the event test job dispatch the test job is located in here so for the moment i won't do anything i want just to fire the test job and i will want to catch it here in the main app so the way to catch it is go to event service provider and i will remove all this code here we don't need it and here add up bind method test job class i will concatenate it with add handle here and this will call a function with a job as a parameter that will call job handle let's update to php 7.4 so if this doesn't work for you if you have a lesser version of php you can use function and you can add job here and return job handle but i will keep it like this because i like it better and in the test job i will remove all this stuff i will just echo event has been handled php end of line so to wait for this event to happen we have to write php artisan we have to go inside the docker container first docker compose exec main sh here on php artisan q work and now our queue is listening to events now let's go to our admin and here we will dispatch the event with the command php artisan fire so this means that the event was fired and we can see here that we are processing seeing the job test job and we got the message event was handled now we are listening to events from one laravel up to another one using rabbitmq and if we seal the chart we can see now an event happened right here and it was processed now that we fired an event let's uh create all the events for creating the product so the first one is php artisan make job product created so the job will be created here and let's go to our product controller so when we create a product here we need to dispatch an event that the product was created and we have to dispatch it we have to set also a product is a parameter but it needs to be an array it's always a good idea to send an array because sending object might not always exist there and the rays always exist now we dispatch the product we also need to add the product here so i'll call it data and i have to initialize it so this is our products created now job so let's copy this code and now in the other app create the same job make job product created let's go to the product created and here we'll paste the same now the same data that is passed on the this job will be passed on this job as well now before we change the handle function let's go to event service provider and here we will add the product created job we can remove the test job since we don't need it let's remove also this imports now let's take care of the handle function now here we have the product data that is created and now we just have to create the product ourselves so product create so if this create is not highlighted we have to use php artisan ide models i explained that in my previous tutorials so so you can check them out if you haven't seen them now create is highlighted now for the product we have to set every field here including the id so the id is this id we have the title we have the image and created that and updated that so that's why we made the id in migration to not be auto increment here so let's see if this works so php artisan q work now let's open our http and we want to create a product now title t image i let's send the request so we successfully created a product oh this is get sorry my bad post so we created successful the product now let's see if it is handled and it failed so luckily we have the created jobs table and field job stable sorry and here we will see the reason why it failed so we have all the data here about the event and the error is how do we see it mass assignment exception so the error is because of the product we didn't have guarded guard it and i will put it an empty array here now it should work let's try again and send a post request so we sent the request again and it failed again because we didn't restart the queue i guess but let's see there just in case so the same error so we have to restart the queue php artisan q work and let's change it now it's processed successfully and if we see the products now we have a product with id 13 title d and image 2y so the same data that we sent so this is how we send events through rabbitmq now let's do the same for the other update and delete so first we have to create the jobs php artisan make job product updated and php artisan make job product deleted here in the update function we'll send product updated dispatch the product to array and in the destroy we will send products deleted dispatch we only need the id here let's go to product updated i will copy the same code here from product created because it's basically the same and in the product deleted it should be an id so i will change these values to id and this is id here i will copy them and go to the jobs here and paste them here and let's go to event service provider and i will duplicate this adhere product updated and here product deleted now let's take care of product updated first we have to get the product which is a product find this data sorry data id and then we have to update it this sorry product update and we have to set the values which is title this data title so i will do it the same as product created here so i'll copy the array here paste it here here we don't need the id because it doesn't change since we find it directly here and for the product deleted we have to use it this is really simple which is product deal product destroy this idea now let's go to our http now we will put to product what was the id there if i remember correctly i'll put 12 here and i will change the title to new title so this is uh changed but it failed let's check the reason update on null so the product id is 13 so it should be 13 because the product with id 12 doesn't exist so let's change it again and it was processed successfully now the title is new title now we have to remove it we don't need to send data so it's removed here it should be removed also here now we don't have a product so this is how we uh send events through different apps and also we are consistent with the data now we want to add the like functionality for the product so first we have to create a controller php artisan make controller user controller now let's go to the user controller and here i will add the simple function i will call it random and here i will get a random user user not this one so it should be user from models in a random order first so with this i just get a random user and in the end i will return just the id user id so if we test this function first let's add it to our api.php and route get user user controller here and the function is random let's try it in our http so this should be get and this should be just user we can see that is a random id here one is 10 18 etc now we want to call this uh end point from our other app so to do it in our product controller here we will add another function like and the like will have a request let's add it also in our api.php so this is a post request to products slash id slash like so we need to add also the id which i forgot this is like here now let's go again to the product controller and add the id which we forgot so now to like a product so i will make a weird logic here but this is just to show you how internal requests happen so i will get a random user from this endpoint which i will copy right now and that user will like this product so to get uh an internal request we have to use http get we will paste the end point and that that's it basically so this is the response and for the moment i will just return response json this will return what we got here so so to test this we have to send a post request to localhost port 8001 since it's this microservice is not this microservice products i'll put a random idea let's put 13 and like any of the body i will put nothing so let's send a request and we can see this will stay forever like this unless we restart the docker containers and now it failed to respond why did this thing happen because the problem is localhost here and when we try to access localhost in a docker container be careful sometimes this localhost sometimes is not and this time should not be local host and we have to tell docker that this is our local local host not the docker localhost to tell it you we have to write here docker for mac localhost it looks really weird but this is the way in how docker recognizes our localhost now let's do the same here send a request and we got the id now we are calling product like here and we got a random id so we are going back and forth we are calling this uh application then this application is calling this other application and we are getting the user id now let's add a migration so i will add here php artisan make migration create product user table so this table is to record all the data that we store in our where the product is like so create product user table this will have an id also we'll have a user id and it will have a product id so this is a product user table we also need to make them unique user id and product id because one user can like one product just once now that we created the user let's migrate also let's create a table php artisan make model sorry product user let's go to product user let's add guarded here i will put id here since we don't change the id here and now in our product controller we'll get the user here and we have to store the product user create we still need to run php artisan ide models here and inside we'll put the user id which is user id because now it's an array and the product id which is this id that we pass here now i will put a track edge here if an error happens means it means that the user already liked this product so here i will return response message success and here i will return response error you already liked this product response from symphony component http foundation http but request now let's try to like gain this product let's log again so we should not get this message let's see what is the real error product users not found so it seems it had it adds an s in the end so it doesn't recognize the table so we have to use here protected table is equal to product user so we specify the table manually right now so it was successful let's uncomment the try catch here and like again so it will come a time that will hit the same user and we will get the error that the product is yes this is it you already like this product so this is how you make internal requests with laravel now that we like the product we need to send an event from the main app to the admin app so let's do the same as we did before let's go inside the docker container and create a job php artisan make job product liked and here we will send we'll call it here product liked we'll dispatch it and we will send this product user to array now let's go to the product like table uh class sorry and now we need the data that we need to send we need to initialize it so this is a product liked in the main app let's copy it and we will paste it to the admin up so the different series that we need to call the handle function but first let's go to the event service provider let's remove this code and here call up bind method product liked class at handle here a function that has a job that handles the job let's switch to php 7.4 the change here does change only the composer.json file that's why it does highlight now let's uh take care of a product like it this is really simple we have to find a product which is product find this data product id and we have to increase the like count so product likes plus plus and product save so that's it we increase the product likes when a product is liked here so we have to also run here php artisan q li work listen works the same but doesn't matter now let's go to our http and run this post to like the product again so i already like the product so let's try again success and let's see the terminal it failed let's see the reason it seems that we don't have the product so product 13 doesn't belong here so what i will do is create a new product now so port 8000 api products i'll create it with a title and an image so title t and image i let's create it and the writing is 14. let's see actually i didn't start to listen here so we can see that it didn't uh process uh in the main app but the product created was processed in the uh admin app which doesn't make sense so to fix this uh problem we have to create multiple queues so let's go to our emv file so first go to queue.php and for the queue we have rabbitmq here which is default queue both of the apps are listening to the same queue now we will change it so we will add this is the admin queue here and let's copy it and let's go to the amv file here and here we'll add the main queue so now let's restart also php artisan queue work also here so now they are listening to different queues but the difference now is in a product controller we have to specify the queue that we want to dispatch a product so in this case i will dispatch the product created on the main queue only the main queue will listen to this one also to this one and also to this one so i made a mistake here it should be here and on the main queue when i fire the product liked so it should be on the admin here now there is no room for mistakes let's restart it again just to be sure and this one let's restart it php artisan q work let's create again a product so product with idea 15 is created and it's processed here so we got the product there and it's not processed here now let's change the port to 8001 and the product was with id 15 like we can send the request again so the message was successful and here is not handled let's see here it's handled so we got the two different uh queues now running parallely and if we see the product we can see the likes are incremented by one so we almost finished up but there is one last change that we will make is this q work we always have to start a docker container and then to go inside the docker container to run another command this happens for both of the apps which doesn't make sense to it all the time and also doesn't make sense to do it on the production environment also so we have to create another service now just for the queue to listen so we will use basically the same docker file here so to create the command we have to add a queue here which is called the main queue it will call the same docker file we don't need the volume because we don't make any changes neither the port we need the db since when the job fails it will store it in the database now we need to run the command php artisan q work but the problem is that we have already php artisan serve inside the docker container so right now what we will do is cut this code here and remove this code and now this will be our docker file now let's go to the docker compose file and we have to simulate that command directly in the docker compose file so here i will write a command php artisan serve so this will work the same as having the php artisan serve in the docker file now we will copy this line paste it here and instead of serve now we will run q work and uh what is left is to restart the docker containers and build them and now we will have a three docker containers instead of two i will do the same for the other app so let's add here the main queue it should be admin q here it will depend on the admin db and in the docker file we have to cut this part here and we have to add it in our docker compose file as a command let's restart also this with a build now as we can see the containers are running if we do a docker ps we will see that we have a main main q and main db now all the other app is running so we should have a more containers running now and if we create a prod product or do anything else so i will call this http by default and one up should handle the so let's open the terminal so this app processed the product liked and if i create a product it should be the other app so this app doesn't do anything here but this app processed the product created and we can actually see it in the database so this is the tutorial about laravel microservices i hope you like it and you if you have anything post it in the comments thank you
Info
Channel: Scalable Scripts
Views: 91,895
Rating: undefined out of 5
Keywords: microservices, laravel, php, rabbitmq, event driven design, docker, containers, event driven architecture
Id: SzsPe_QX__c
Channel Id: undefined
Length: 88min 5sec (5285 seconds)
Published: Thu Oct 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.