In this session, let us learn about hystrix dashboard hystrix dashboard is used for monitoring the historic status of any application. I am going to work on the same application that we have done in the previous session. Let me first show you the pictorial representation. Now, we had Eureka server and three services, the three service portal service, then you re apply. And then Eureka hystrix. All three are micro services only.
You don't have to give the name of Eureka, Eureka Eureka client, you can have the most proper names like book service Inventory Service order service, like order service, trying to connect to an inventory service to check in for the inventory whether it is available or not. In our case, these are the three services and Eureka is six was trying to connects to Eureka. Eureka client is trying to connect to a hotel service portal. So it's only going to use in the star hotels to Eureka client, which in turn is returning the list to Eureka hystrix. We also had few other methods, all the three are micro services, so they have registered themselves to Eureka server. This part is clear.
Now, what actually I'm going to do is I'm going to monitor the historic status of this particular micro service, because here only we have created the callback method. Now in this case, we have annotated classes at the rate enable circuit breaker. When you run the application, what happens it is born call the original method. If the original method throws an exception, if any of those micro services down are if the database is not available. In our case, we don't have a database, but if the database is not available, in this case, the fallback method will be called Continuously only the fallback method results will be shown in the browser. But in case if the number of requests are more than the threshold, in that case a circuit breaker will open up a circuit will get open.
You can monitor this in the hystrix dashboard. That is what we are going to see here. Now I will go back to my application. So this is the hystrix controller. Here we applied with new hotels, because giving the list of hotels and also getting one hotel by ID when we were trying to solve a flash username, we were getting any error. Eureka client was working fine hotel service was working fine.
Only this particular application was giving an error. It was because of the producers part. I have remoted now it is working perfectly fine. What are the steps? First you need to run Eureka server then water service, then you recognize Eureka hystrix In my case, all the four are running I'll open the console. You can see over here, Eureka server portal service Eureka client and Eureka hystrix.
Now let me go to the browser. So this is the browser showing the registry. Let me refresh it. Here I am getting all the three Eureka client Eureka has six and hotel service. Let us try to open one by one, I'll click 8081 that is hotel service. Here the URL all hyphen hotels.
It is giving me the list of hotels. Again I will come to your a car client. In case of your a car client we had some players hotels only internet is calling hotel service and returning the list of hotels. The same output only. Now we will go into your a QA is fixed in America is six. Now what they will do is I want to call new hotels which will return a list of hotels.
I have got the output here. itself. Let me also show you getting one hotel by ID and checking Hello class username, new hotels slash 127. Now I have got the output. Similarly, let me try this Hello, slash username, it comes off. So all the three services are working perfectly fine.
Now let me open the hystrix dashboard, how to open it with the same URL only localhost colon 8080 slash hystrix. I'm getting the dashboard. Let me copy the same URL. I am supposed to call it using hystrix dot trace, you can just see the URL over here. In this case, we are running only one single single effects application. So the URL is going to be http colon slash slash hystrix app colon port number slash hystrix dot c. So I'm just going to copy it over here with Dr. Ben, click monitor See, you can have a look, whatever method we have called is shown over here, find by ID grid Finder.
Let me open Eclipse, grid, find by Id find all these are the three methods. And again, I will come back to the browser, all the three methods are working fine, whatever the third, the third, you disclose. Now, what I will do was explicitly I am going to shut down one service. Let me shut down Eureka client. I'll go to a clip here. I'll select Eureka client.
I'm going to stop the service. The Eureka client is terminated. You can see over here now, I'll go back to the browser. This is Sarah Do you see let me refresh. Here I bought hotel service and Eureka is six only you a client we have terminated. Now again, I'm going to the 083 slash farmer slash ramp.
Let me refresh. I'm getting the fallback method Can you see the output? Now again similarly, I will give new hotels, I must get the fallback method of course and getting the fallback method, I will go to his fixed dashboard, what has happened you are trying to call the method This is a request, what are the requests the number of requests is very less. So, the circuit is still close Can you see in all the three methods that are to disclose what leaves the number of requests are going more than the threshold level, in that case a search will open. Now, what I will do is I'll try one with one method. So, in our case it is find out that is the URL as new hotels.
So, here you can just see, I'm just refreshing it again and again and again and again. You can do this are you can copy paste it in different browsers sorry different tab. So, here I will refresh continuously. Now, we will see The dashboard. Now still the fact that the number of requests are more can you see this? And again, I will continuously do this.
I'll come back here, I'll refresh this like you disclosed. Now, let me still do it. I have done it a number of times. I'll go back to the dashboard. Now, you can see the circuit is open. So, I refer to as clear, what actually has happened is, we are having a micro service, this micro service is trying to connect to one other micro service, the other micro service is down.
So automatically the showing us the fallback method is the number of requests left it will try to manage it keeping the first to close that is what we have seen, only the fallback method was given to the client, but still the circuit was kept close. But when the number of requests are more going beyond the threshold level, automatically, the circuit opens. Now, we need to clear up again after a predefined text automatically flows. I hope it is clear, this is all about hystrix dashboard. In this case, we are trying to call from one micro service to another micro service is called micro service is not available. In that scenario, the calling micro service has to show a fallback method to decline.
We have seen the results directly in the browser, what actually we can do is we can create a client which is a web application trying to connect to that micro service. So, in the next session, let us see how to call a micro service from a web application. Already you know how to call a RESTful web service from a web application, we are going to follow the same thing only. But in this case, the micro service or the restful service is going to have is fixed attached with itself. If any of the micro service on the floor is not available, it should not throw the exception to the client. Instead it should give the result of the fallback method.
So I will show you a full fledge complete example in the next session, together with height hystrix. Thank you