Designing Microservices using Spring Boot, Spring Cloud, Eureka and Zuul | #2 | Tech Primers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to tech primers this is the continuation video from the previous video so in the previous video what we did is we created a micro-services design pattern for an application called stock price viewer ok with that application we came up with a design so this is the design which which we had designed our architecture for micro-services design pattern and we started developing microservices right so what we did is we created DB service we created stock so we created a service registry which is a Utica service and then we had some issue with the Yahoo Finance API so that is where we left right so I I actually recorded this particular video some time back but what happened was since I tried creating so many micro services my laptop couldn't handle that and then it got crashed so the whole video went off after an hour of recording hold video went off so I what I had to do that reboot the whole code and I am going to recreate everything for you in the same video again ok so what I'm going to do is I'm going to merge the API gateway and the service registry into a single process so that we will save some memory did so I don't want to and also I will not create the code maintenance service because it's just the add and deletion of the codes for a particular user so I'm not going to do that I will just leave it to you guys you can go ahead and try that out ok so what I'm going to do is I'm going to create the Zul proxy and I'm going to merge the Zul proxy into the array cur service ok and from this TOC service we are going to use the eureka service to connect to the DB service so that we didn't do in the last video we had a URL hard-coded but we are going to change that that's what we are going to do first suppose we are going to fix the Yahoo Finance API it was not working right so I found the fix so I'll make that and then we can work on it right so so this is the place where we had the problem alright so what happened was we retrieved the stock price information we got the stock but what was happening there was an exception throws a 500 internal exceptions right saying that I charged ahoo dot-com was down or something so I saw that Yahoo has a decommission this particular API they are not going to use this API anymore so but still be it works so what I'm going to do is I'm going to slightly refactor the code so I'm going to say it's top of the code so we are going to get only the pricing information right so what I am going to do is I am going to create one more photo so that this price information is left there okay so we'll just create a table here called stock okay it has a stock now and I'm going to say create a code and the first information is going to be quote and the second information is going to be stock cake code . k trice so this is going to give the price of a stock okay and i'm going to create a POJO so and just creating an inner class so that we can use it okay so let's use IntelliJ feature to create parameters which is a quote cake or I'll just a great price and finally I'm going to say Gators and Shiva types okay cool my poacher is ready so I have the object as well here and I need to return the same object right so I need written the code objects right so they should work now I need to do a return here right so this should work so we are going to test that meanwhile if you notice here what we have done is we have hard-coded the URL of the databases right so we should not do this we should not hard code the path of database service we should be using the Eureka service to retrieve the database service information and route request so we created the Eureka service the service registry because of this only so we don't have to hard code the URL in this in this process so we don't have to add code the URL of stocks of DB service inside stock service that is why we have the service registry so they say service registry by providing a service name so for the Debbie service the service name is DB - service so let's bring up the eureka server and I will show you why I chose that name right so when we bring up your wrecker server and when we bring up TTP service bring up T visas also the TV service will register to the Eureka service under the name called DVI sensors so that name comes from the applications or property so we have named our application and spring application or name as DB service 8 so that is the name with which we will be now calling this over so if you see here the URL is vo right so this is how the discovery service is going to work the service registry is going to work basically so Eureka will identify that okay I have this particular name okay I'll go and check in my registry and then I'll route it for you so additional to that what we need to do is we need to go to the configuration if you see in the rest template we are going to use Reston plate to do this right we are doing a res template or exchange interesting plate we have to do load balancing so we have to do client-side Road balancing so you have to add this annotation called at load balance if you see in the previous video I added and deleted it but we need to add that so that there is a client-side code balancing which will take care of resolving that URL so it will go to service registry and resolve it so that is why we need to add that at load balance so if you are using a normal test template and you don't use any service registry or any other framer you don't have to add the at load balance you need that specifically for the unica service ok so if you see what is happening I think DB service is not coming up I think this is because database is not up so I haven't brought the my sequel up let me go and quickly bring that up meanwhile the Eureka server should be up let's go to the Eureka server and check the server alright so right so what are they to do use a very much it go so I'm just talking the my sequel so okay so good so our my sequel server is started yep its success so let's go ahead and quickly start the TB servers which failed because David sellers was connected to the my sequel database but since the database was down it was not able to connect and with connections were failing and that's why the process was not off and if you notice here Eureka solar is already up so it is having the dashboard and there are no services running right now okay so we have started TP service let's see if the DP service is getting registered and let's say I think main while I can also start the stock service side to save some time so let's go and start the stock service also okay I'll just move this table with us right okay so if i refresh this page you should see some information yeah if you notice here's already DP services registered to the Erica server let's wait for the stock service also to register one stock service is registered we will now hit the stock service and internally we had changed the you are and right now the stock service is going to use Eureka to route to the DB service okay that is what we are going to check now here so I will just keep the URL ready so the URL for stock service is 8301 and this is going to be the URL right red slash stock so let's hit it and see all right so there is a ribbon load-balancing error I think this is because the load balancing let's see if the record register yeah so the DB service is registered so we have the stock service and the DB services both register let's go and refresh this URL if you see here there is a exception in the ribbon client no class definition error cannot account means okay I think it is because the server is not completely up alright and I think I hid the rest endpoint before that let's check quickly what to say I'll just clear this often then I'll restart the server so I have configured at 10201 de ok now mr. solos right fine let us come up first and we will hit that restrain point after tip we stood right we were troubling it something back but here okay it is off now it has gone to the discovery Claudia let's go and check if it is connected to miracles all right so let's go and check in the Erica so what if these doctors are still showing up now so it's showing us up now we can hit the rest in point so now this is going to hit the TB service and retrieve the stock information for the Peter so it is going to go to the DB service yeah it's working it so if you notice here okay the DB service went the stock service went to the DB service queried whatever all the course which are available for Peter and then it to retrieve the stock information okay if you see here there are three your stock codes assigned for Peter so if I let's say I want it for Sam it will go to Sam's information so Sam has only Google so it went to Sam's it went to the database and retrieve the quote for Sam it is Google and using that Google it went into the Yahoo Finance API retrieve the price information and it is showing up in the UI okay so what we did here is we are what we did here is from the stock service they connected to the service registry from the services sheet went to DB service it got the data it came to the sock service it went to Yahoo Finance API to treat the data and then we got it okay that is what we did here now what I am going to do is I'm going to create the API gateway and embed that into pee-yew wrecker service okay that's what I'm going to do now so let's go to the you decker service so we need to do in order to embed that we need to add the dependency form dependency so the dependency is spring cloud starter zone this is the dependency which we need to add so the version which I am adding is 1.3 dubsy row early okay so this is going to have the Zul proxy enabled in this particular project so as you know spring boat has this way of having annotation so we need to add the annotation for Zul proxy hazard so we need to add the enable zone proxy annotation this is going to make this particular process behave like a proxy okay it is just going to be like a proxy so it's just going to be like a bypass system okay so how will be till spring booth or how will you tell Zune to be a proxy so we need to add some property so I already have some properties here so I'm going to add the properties for the DB service and the stock service right so what we need to do is we need to give the URLs of the TV series and stocks of this here okay and we need to give the rest endpoints of these okay so if you see here what I am doing here is I am just configuring the URL on the path with which we need to connect the DB in the stock source okay so let me finish it and I in till you okay so what we have done here is we are saying that every rest in point which comes in a slash API needs to be proxied okay which is Zul protected now under api if it is having DB service go to this particular post okay if it is going to have stock service go to this particular post that's what we are doing here so we are basically having two registered hosts two registered services one is the DB service and the stock serving so this is going to be like a proxy so when any request comes in it indirectly redirects to 8 3 0 0 8 3 0 1 and this is basically running in a 3 0 to 1 if you see this this particular process is running in the 48 3 0 2 okay so yeah see this right it particular this particular process runs in a 3-0 - so if you hit a 3 0 to port number it is indirectly going to go to a 3 double 0 8 3 double a 3 0 1 that is what we are going to do ok that is what Zul is for so that is why this API gateway is in place here so it is just going to be like a proxy so whenever a request comes in ok it goes to the sock service ok or it goes to the DB so is directly so literally we are doing micro services inter-process communication using VAP gateway and from the stock so it is going to use the Eureka service to figure it out what are the microservices not yet and it can connect to that that is all we are using the you take a design pattern basically the server suggests a design pattern right so we have now designed the API gateway now we need to hit the restraint points right with this particular API slash whatever so let's restart the Eureka's over the raker service basically mean well let me check if the videos getting a folder yeah it's getting recorded yeah last time what happened it was I as I said earlier so my video got corrupted and my system got a started and I had to divert everything and do it again but yeah this time I'm very cautious so okay so I think it has registered it's trying to register the clients I couldn't find so that's why you that exception came so let's go and check the dashboard and confirm that all the registrations are done and then we will ship T yeah so the registrations are done so the clients are registered to the wrecker server now if you see the URL for this we are going to use this particular URL so previously we access we used the stock information of Sam with directly hitting these talks of the state now we are going to use the API gateway so we are going to say API slash stock - service okay and then we will have a red slash tok slash peter right just what is going to happen is let me do some so I think knowing since available for tb3 this because the it takes a while for the service to register so that is what is happening that's why it's still showing it yeah it is working so yeah so if you notice here previously we had used the URL called 8301 with which we directly hit the stock service now we are going to use the api gateway you using the api gateway we are using the stock - service and retrieving is talked for beta okay if you want to access the TB service we will do this we will use the TV service and we will do DV and if you notice these are the stock coats for the Pater for the username Peter and this is directly going to the DB service from the API gateway okay previously when we hit the stock service it went to the stock service from the API gateway stock service internally use the array car service to identify the DB service and it was internally using this right so literally we have gone through three or four levels of micro services what he called navigation so we went to API gateway from there it went to stock so come there it went to service registry and from there it went to TV service ok that's what we did there right so now we need to create a UI and we need to integrate that into the UI right so how are we going to do that I already created a sample UI code let me open that let me open that inside sublime text because last time what happened when I opened it I opened it inside Visual Studio and it got screwed up so I don't want to screw up this time right so I have only two files one is the index dot HTML and the other one will be after at HTML app dot J so it's emotional it's good and just make it bigger okay good I think this should be in a strike yeah so what i'm doing here is the index.html is a basic HTML file so i'm not going to run any tomcat or any web server for running this particular angular JS code so it's just a simple HTML page you can run that client-side angular angular JS right so that's what i am busy so i am going to add the angular library as the script dependency here and i am going to include my script the other side the apt of g is Phi which is going to have a controller okay and coming to the the UI part so I will have something called username that is just a text box and there is one more textbook code and I have two buttons one called add and one called retrieve price so ad is going to add the quotes for that particular user and retrieve price is going to retrieve the code information retrieve the price information from for that particular user whatever codes are there configured in the database you can retrieve all those code information and those prices okay so I'm using the application so my name the application is called my app so I have created an angular application here so and related angular module called my app and I have tagged that ng app here as my app the controller which I am going to use as my controller it's just I am just a liasing it as ctrl and when I click on the button I have some action items here so I just say ng click so retrieve flies will now call the three method so if I go to the tree method I can see what it how what happens indirectly mother in the tree method I have this URL here right so this is nothing but the URL with which we are going to access or be just accessed right so if you go to the browser right we just access this you so this is the same you are whatever we access so this is going to be the gateway URL if I go to the diagram here can see it so the UI is going to have only the gateway URL it is not going to have any other stuff that is what we have done here okay that is what we are doing here and so it is going to go to stock service and retrieve the stock for that particular name whichever we provided in this username text box okay so whatever name you provided in the username text box it is going to query for that particular user okay and the response is going to be pushed inside a variable called codes and that codes I am just doing it here making it okay so under and for the other method so if there is a if there is the add button action which got triggered that will now go and push the quote information for the user into the database so I don't know if it works I just tried in my previous video but it did not work because I was doing something wrong me but I can show you in postman so what I will do is I will push that to the postman and see how the code got changed or something like that okay so I'm just doing a post here and if you see here instead of DBH sort of stock service I am going to use DB service and I am doing an ad and then I'm giving the JSON message and I'm pushing that into the same quote here nothing else okay that is what the UI is going so you the UI is basic simple one so if I open the UI in it let me open the UI and show you what is there in v1 so this is what is there in the US okay so the UI is going to have a user name field code ad and rightly so what I'm going to do is I'm going to say Peter and I am going to hit the retrieve option okay this is going to run the rest endpoint which we did here and if you notice here it ran and already we got the results here okay because the stop my information so literally we have access the API gateway okay we from the UI we access the API gateway it went to stock so it went to services tree it went to TP cells collected all the information collated it together and then it pushed it to the US that is what I am up in here right now okay so that is what has happened here okay so if I say I want to add one more quote into Peters name right so for example let's say I want to have a tech class okay I want to address class stock information I click on the plus button okay it is working cool so once I click on the plus button it ran the BB service so it ran the DB service with the add option so if you see here what we did raise the van the add option with the Jason matures which with which the DBA is expected so if I go to the TV so visit the DB service was expecting and add option actually the client the quote maintenance service is supposed to do that Oh V okay but the I have directly Tang back from the API gateway it's us because it's not required actually I just figure that out with the code maintain service is not required because the respond endpoint is already inside DB service so I city here it has come here it added the code information and it is really the what all codes are there for the particular reason and it is showing up in the UI so Tesla code got added to Peter and if I now do a retrieve price Tesla code also should come to the UI if I see here yeah Tesla price is 350 fine so that also has come so if I need to display this into a meter format rate I don't know if I can let me try right so what I will do I will just try displaying this in a neater format I'll just put a table so table TR T H so coat I'll just have a cold and then what else I have rice right this is already there and now I need to do the ng-repeat options right so what I will do I will just say ng I won't repeat right and I need to repeat codes in code okay and I'm going to say this is going to be co dot what is the code it's going to be code why did I name it as code I don't know okay okay so this is what is going to happen and the next one is a price right we need the price is it dry is it called a spicy are described it's called as price and I am going to close this and I'm going to close the table that's it let's see if the table gets refreshed and I will just remove this code right let me refresh this and make the UI better I think something happened something failed all right so what what fail I think something in angular only fails because maybe I messed up the syntax here let me see if that is the problem no that is not the problem whatever things are stark parity are deepening right so I had a coke vehicle it existed a ng-repeat so what is the problem for it is kind of let me quickly go and then so the ego thin sorry injera paid in and below okay X in records okay whatever I did previously work okay whatever this is correct right okay and why did it fail okay the table going displayed okay I can activate it yeah that's what I have done here the quote and then I can say quote dot quote because that is going to be a JSON so let's do first is going on cuz there is a problem I think why let's go to the after Jess is the time I think there is already an optical code already so what I'll do is I'll just say this ask you and then I'll just Union this is Q so that nothing gets messed up and I'll - first this page still not working and I don't even see what is the problem so let me come on this guy and then still now it should work all right [Music] and just plenty codes sorry something got screwed up guys so what quad CUDA up I'm not sure did we add anything unnecessary actually I didn't add anything which is creating this problem what did i do from the beginning [Music] into this water eject okay this may be firsta page yeah something is working out for it right so now let me paste that code which I had in mind right and refresh it okay good it is getting this plate now let me the motors and then I am just reverse this page cool our code is not working now if I say Peter and if I say the trip price this is going to take the pipe yeah I can see that so the code for Google is this Apple is none waiting to hit Amazonas whatever tip flies whatever yeah that's it so if I have to have one more quote information added let's see for family so for Sam we let's retrieve the place and we like them so for Sam let's add a tester right so I'm going to say act okay the test lab size is going to be added so just a code will be added and I think it won't be displayed because we did not have it yeah I think I added twice just laughing cool so it is working so this is the angular web UI whatever we saw in the architecture diagram so we have created a web UI we added the code information whatever new quotes information we have added whenever we do a retreat those are getting retrieved okay that's what we did and how we designed is we created a zone API keep a proxy and then we merge that inside the service registry which is the Eureka's over we named it as you take a service okay that will be the project name inside the project you can check the product in the github in the github repository I have put that there and we are going to have a stock service stock service is going to go to the Yahoo Finance API and to take the stock price information real-time PB service is going to store the code information of for each user what are all the codes he has registered to okay so that is what we did and D we're communicating from the stock service to the DB server is using the service registry of the unicursal okay so that is where you record comes into picture and we did not design the code maintenance of it because it is not made any sense right after we started designing et cetera promote so as you can remove that it's not out of scope right now okay so that is it that is what I wanted to show but that there is one more thing it is notice here we have not taken care of any resiliency right what if the stock service goes down what happens to the message right what happens to the UI do we get any exception right let me bring that down right so let's bring the stock service down okay I have brought the stock service now now let me go to the UI and then retrieve this talk okay nothing is going to work it's not even saying anything right we should have said something so we didn't had any add anything there right so that is the problem isn't it so we can have different design patterns inside this micro-services architecture so there is something called the history design pattern so same way net Netflix as they are created that okay we can use that to thin pattern to come up with a fallback mechanism so if something is failed or something goes wrong you can go to the fallback and then you can open the circuit so any subsequent requests will be failing and then once the service is up you can close the circuit so that the subsequent echoes are successful so that is one type of design patterns Cystic since one table is in Batam one more thing one more problem which we will be facing in the micro services is the log traceability okay how will we trace the log right some day be serviced in the UI right right on the you identity becomes how do we trace the logs right that is a challenge right now in the micro service industry so there is a library from Spring itself it's called spring cloud sleuth I have also made video on that already separately where I would have shown and I will deployed it into a cloud in moments why you I deployed it into a vertical foundry and I showed that example so they have to use that as well so in this particular example we I haven't show that but it's just a dependency which you have to add the form protection one so that you can have the trace ID right from the start till the end so you will have span area increase ad concepts so you can check my other video - no in depth of what is spring cloud salute on over okay so these are different problems which we face in micro service there are so many other problems as well for example if you scale the application if you introduce new version of stock service if you introduce new stock service new DB service how will it route automatically to which service how will the api get wear out right now we are reacting to a single port ID how will it route so in that case we have to route API gateway itself to the service registry from the service associate has now automatically choose which one is balance and stuff like that so those things are there so these are the different things which we have to consider when designing Microsoft okay it's not that easy to say okay I am going to make your service but make sure that you guys are aware that okay these are the things which you need to take care one going to micro service design pattern okay so I hope you guys found this video interesting and you learn something from this particular video if you liked the video go ahead and like it if you have any doubts go ahead and drop that in the comment section below I'll be able to reply whenever I see it meet you again in the next video thank you very much [Music] you
Info
Channel: Tech Primers
Views: 74,514
Rating: undefined out of 5
Keywords: spring cloud zuul, spring boot cloud, spring cloud eureka, spring service discovery, spring resiliency, spring cloud zuul eureka hystrix, zuul example, spring cloud zuul example, spring boot microservices, microservices example using spring boot, microservices using spring cloud, microservices using spring, spring cloud microservices, microservices example in java, microservices example in spring boot, microservices example in spring cloud, stock price viewer, netflix eureka
Id: ifBFwH59gGA
Channel Id: undefined
Length: 34min 8sec (2048 seconds)
Published: Fri Aug 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.