Microservices Architecture Zero to Hero with Implementation using Laravel and RabbitMQ | Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello I'm hania and this is another video from my channel in this video I want to talk about microservices which have gained more attention over the past few years in this video You're gonna build an application with microservice architecture it's very exciting so let's start first let's talk about the monolith and microservice architecture and find out what's the difference between them Vector all business logic and the modules are contained within a single repository all data in this application is stored in a single database all services and the modules in a monolith architecture will be deployed and managed in one place and you can't decompose the services and use different places and the servers for each service microservice architecture is different from the monolith by using microservice architecture you can decompose your services into independent components which means each service will have a separate database and business logic and separate modules like monolith architecture different deployment and monetary approaches can be used for different services in this video a market application will be deployed using the microservice architecture and laravel framework that will handle the buying and the selling of products as you can see this project is composed of three different Services product service order service and delivery service will have a separate database and will run in a different container as you can see each service is connected to the rabbit and queue to use it for their communication if you don't know anything about rabbitmq don't worry we will cover it later in this tutorial we will focus on and build completely two of them products and Order service if you like this video and want to build the delivery service too please let me know foreign service and product service will communicate together communicate together by dispatching and consuming events actually the user will create an order by sending a post request to the order service and the order insert into the orders table and the order created event with this patch to the event bus that we will use rabbit in queue product service will consume the order created event and based on the data inside the event the inventory of the related product will be updated so first let's start with the product service because the order service will is depended on their products so we should have this service to install get delete and update the products as I said before we are going to use laravel for our services so create a new new laravel project and let's go to directory and create new Largo project with this command composer create project laravel slash laravel and the name is product service after creating this project I will dockerize the project if you don't know how to do this make sure to check my video about darker and I will put the related Link in the caption I don't want to talk about the rising process because it's very it's very long process and you can check this uh by yourself and that's it our product service project is ready so let's go to dockerize our project as you can see the project is running on port 8080 on my Local Host just by running Docker compose of Dash decomment if you don't if you don't want to check my YouTube video uh you can just go to my GitHub profile and clone the docker larabelle repository and work on it also there are some notes that I want to share with you about the crising that yaml file I will change the name of services and also their container name for example the engine X service is a product nginx now with a product engine X name for its container and also the product DB series the product DB container and also the application service has the product app name with product app container name also make sure to change all these changes in your environment file for example I've changed the DB connection to postgres DB host is the product DB service and the port of database is for 5432 and the database name for product service is product and also make sure to change your product at your application service name in your config file our nginx for example in this project it's a product app service you can you can check this in your Docker compose file and it's running on Port 9000. go check this and it's correct okay the product service will just have a table for storing products so I will create the products table for this service stacker compose execute product app uh PHP artisan make my creation create products products table okay it's created let's go to our migrations and that's it the products table will have an ID a title title and the price of product [Music] and the out inventory of product which this inventory will decrease after um creating an order the products table is gonna have a model so let's create the Docker create a related model with product name product app PHP artisan make model product it's created on the on this in this directory so let's create it app models and it's our product model this model has some fields to be filled so let's define it protect it label attribute will have a title price and the inventory okay that's it now we have a products table to store the information about the products and its related model to write our controller so let's make a controller with product can controller name the product controller is gonna handle our code functions and I will cover the index store show and the destroy function of a crowd so let's define the related model of this controller product model and it's defined Constructor of product controller public function construct products Pro dogs [Music] write it again product because import it now uh this is the next thing that I want to talk about public function is store Quest request I don't want to cover the validation things because this video is just about microservice it's just just let's make it easy and the product will be created just by calling the create function of a model request then let's return a response is Jason the data is the created product and the response is gonna have a message item is added says fully okay test the next function is index it's gonna return us all products this model oh and it's gonna return Jason and the data is lifestyle products without any message the next function is our show function It's Gonna Get Us specific product return response [Music] Json data is product without any message the last function is this destroy it's gonna delete specific product is deleted and enter response message will be set message item is deleted success fully okay the pearlite controller controller is done let's go to roads and Define the API resource type Road for this curled API resource products and it's gonna use product controller class and that's it so let's go to postman and test our API okay so let's test our product service API for example first I want to send a post request to create a new product uh the title will be product to price I want to change this to 50 uh dollar and inventory count is 10. so let's send the request okay the product 2 is created and let's change the title or price to 70 at the inventory to uh 15. as you can see the product tree is created uh two so let's get the list of all the products with a get request and that's it this is uh the list of our products in database so let's get a our product two with the two ID and it's gonna return us our product and also let's delete delete our uh product to send the delete type request to uh server item is deleted successfully so it if I uh try to get this product I will get the not found HTTP exception and if I want to get list of all products I will get just one product with ID 3. okay now you have a product service which is an independent service and it's working fine the order service is as simple as the product series in this one we Are Gonna Save the information about orders and after creating an order a job will be dispatched to the rapid mq and the product service will consume this job and update the inventory of the related product so let's create new project composer create project larabella slash laravel sorry Laura and the name is order service okay so let's create this project open this project in our zip code and the cries over uh project let's create a file a little bit folder with SRC name and copy all this file inside this RC create the docker composed yaml file create a folder for nginx configuration and okay and another folder for PHP Docker file okay um go to my GitHub profile and copy this Docker compose the tml file are in the order service I want to use um MySQL and my order product service used postgres and the side that I want to use PHP my admin let's change the name of um servers order app order DB and make change the container name order app order app order PHP my admin and it depends on order DB the database name is order the root password is password and and and then that's it let's change the uh this port this port in a darker compost because their products app was using this port I want to change this to uh 9001 and also let's uh add our the curve file Docker file the Scoopy and paste it here and the default configuration of engines let's copy it and the paste and there is something to change please make sure to change this uh a service name to order app because our application service name is order app and change your environment you we are using MySQL but our DB host is order DB and the database is order username is root and password is uh password okay let's go to order service and run application oh sorry I have to change the port of nginx for example I want to change to 88 T1 and the database Port is located and the application Port is uh changed okay so let's run it again okay let's open the port 8081 [Music] and this is our order uh service the docker Rising the project Let's uh create a table to store our orders with this comment docker compose execute the order app PHP artisan make migration create orders table it's a simple table you know it's has just unassigned big integer product ID and and it has integer sorry teacher count our products that we want to order okay the order model is the next thing that I want to create order okay this model is gonna have uh the orders the table The Columns inside it's label attribute it will have product ID and count and that's it so let's go and create our order uh controller controller third controller this controller has just a function for storing the order so it's defined there related model for this controller it's a model and the public function um construct order model this model is okay let's define our store function request request and order is this model this model create request all through without any validation and then return risk pounds order okay uh we're done with order service just let's go and test our API with post okay so let's Define our road route uh sorry post orders and Order controller class and the Color Store function from this class foreign okay this is our API endpoint and I want to send a post request a store and order the product ID is a tree and the count is one and as you can see the order is stored let's change the product ID 2 4 and the product is stored in database okay in this video we created two uh independent service first one is product service and the second one is order service the video we will learn to communicate this to Independent service with rapid mq so let's go to the next video
Info
Channel: Hanie Asemi
Views: 7,584
Rating: undefined out of 5
Keywords: microservice, laravel, rabbitmq, messagebroker, docker
Id: yijlKmVl7W0
Channel Id: undefined
Length: 30min 18sec (1818 seconds)
Published: Tue Mar 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.