Spring Cloud - The Final FALLBACK
Yes, the POST name The Final FALLBACK is absolutely inline with what we will discuss here.
We are talking about HYSTRIX-THE CIRCUIT BREAKER, which provides the FALLBACK functionality in Microservices architecture.
The Code can be accessed at GITHUB
Hystrix - The Circuit Breaker: The fallback mechanism is one of the most prominent and important partner in a microservice landscape and it can be implemented with Hystrix in Spring Ecosystem.
The vivid documentation can well be found at the official Site. Here is the basic implementation of Circuit Breaker with Hystrix.
Our architectural landscape is almost similar to the following:
The incoming request first arrives at the “GATEKEEPER”(ZUUL has also got RIBBON), which routes it to the Feign Client, which is both “HYSTRIX” and “RIBBON” enabled.
The “RIBBON” does the Load Balancing work smartly, and which we can see in action, if more than one instance of the service (here AUTH-SERVICE) is being deployed. Now, when the requests arrives for service not all the requests are being served by the same service endpoint, but being taken care by the instances being deployed and chosen by “RIBBON”.
The role that “HYSTRIX” plays in this overall landscape is providing Resiliency to the overall architecture.
What will happen, if out of multiple instance of the same service one gets out of action or somehow all of them are out of action.
Then “HYSTRIX” comes into the picture. “HYSTRIX” with its fallback feature takes care of that. Actually the method that we will be mentioning in the @HystrixCommand will be called when any service fails to respond, i.e. the Circuit Trips…..
This is very in brief about “HYSTRIX”.
Spring-Cloud-HystrixDashboard: This Project helps to view the Hystrix Dashboard. When we feed hystrix stream to the dashboard, it reveals a real time monitoring interface with lot of information.
In this project we have annotated the Spring Boot starter class with @EnableHystrixDashBoard, and there is a controller that forwards it the control to hystrix/index.html.
We have made this service to listen at 8767.
So, when we hit http://localhost:8767/hystrixdashboard, we got the below interface.
In the above screenshot we see that we fed hystrix dashboard with a URL http://localhost:<<port>>/clientservice2/hystrix.stream. This link is of the project Spring-Cloud-Client2 and it signifies that the component to be monitored is CLIENT-SERVICE2.
We have implemented Hystrix fallback in this project i.e. Spring-Cloud-Client2 (for calls to the AUTH-SERVICE) as discussed in the previous topic and annotated the Spring-Boot starter class of this project with @EnableCircuitBreaker.
Now, to get the Real-Time stats while we hit the service through CLIENT-SERVICE2, if that being HIT or MISS (in case AUTH-SERVICE down), we need to feed the stream to the Hystrix DashBoard and which is available at the URL http://localhost:<<port>>/clientservice2/hystrix.stream, with the help of AMQP dependency.
spring-cloud-netflix-hystrix-amqp internally used RABBITMQ
Once Hystrix DashBoard starts getting the METRIC stream from Client-Service2 with the help of AMQP, we get the following screenshot(Provided AUTH-SERVICE is up and running).
Now, we have made AUTH-SERVICE down and we get the below one:
The Code can be accessed at GITHUB
In case of multiple Fallbacks, as it obviously would be, we can go for Turbine, which provides a consolidated DASHBOARD for monitoring purposes.
We are talking about HYSTRIX-THE CIRCUIT BREAKER, which provides the FALLBACK functionality in Microservices architecture.
The Code can be accessed at GITHUB
Hystrix - The Circuit Breaker: The fallback mechanism is one of the most prominent and important partner in a microservice landscape and it can be implemented with Hystrix in Spring Ecosystem.
The vivid documentation can well be found at the official Site. Here is the basic implementation of Circuit Breaker with Hystrix.
Our architectural landscape is almost similar to the following:
The incoming request first arrives at the “GATEKEEPER”(ZUUL has also got RIBBON), which routes it to the Feign Client, which is both “HYSTRIX” and “RIBBON” enabled.
The “RIBBON” does the Load Balancing work smartly, and which we can see in action, if more than one instance of the service (here AUTH-SERVICE) is being deployed. Now, when the requests arrives for service not all the requests are being served by the same service endpoint, but being taken care by the instances being deployed and chosen by “RIBBON”.
The role that “HYSTRIX” plays in this overall landscape is providing Resiliency to the overall architecture.
What will happen, if out of multiple instance of the same service one gets out of action or somehow all of them are out of action.
Then “HYSTRIX” comes into the picture. “HYSTRIX” with its fallback feature takes care of that. Actually the method that we will be mentioning in the @HystrixCommand will be called when any service fails to respond, i.e. the Circuit Trips…..
This is very in brief about “HYSTRIX”.
Spring-Cloud-HystrixDashboard: This Project helps to view the Hystrix Dashboard. When we feed hystrix stream to the dashboard, it reveals a real time monitoring interface with lot of information.
In this project we have annotated the Spring Boot starter class with @EnableHystrixDashBoard, and there is a controller that forwards it the control to hystrix/index.html.
We have made this service to listen at 8767.
So, when we hit http://localhost:8767/hystrixdashboard, we got the below interface.
In the above screenshot we see that we fed hystrix dashboard with a URL http://localhost:<<port>>/clientservice2/hystrix.stream. This link is of the project Spring-Cloud-Client2 and it signifies that the component to be monitored is CLIENT-SERVICE2.
We have implemented Hystrix fallback in this project i.e. Spring-Cloud-Client2 (for calls to the AUTH-SERVICE) as discussed in the previous topic and annotated the Spring-Boot starter class of this project with @EnableCircuitBreaker.
Now, to get the Real-Time stats while we hit the service through CLIENT-SERVICE2, if that being HIT or MISS (in case AUTH-SERVICE down), we need to feed the stream to the Hystrix DashBoard and which is available at the URL http://localhost:<<port>>/clientservice2/hystrix.stream, with the help of AMQP dependency.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-hystrix-amqp</artifactId> </dependency>and it is by this way Hystrix DashBoard provides us with the following feed.
spring-cloud-netflix-hystrix-amqp internally used RABBITMQ
Once Hystrix DashBoard starts getting the METRIC stream from Client-Service2 with the help of AMQP, we get the following screenshot(Provided AUTH-SERVICE is up and running).
Now, we have made AUTH-SERVICE down and we get the below one:
The Code can be accessed at GITHUB
In case of multiple Fallbacks, as it obviously would be, we can go for Turbine, which provides a consolidated DASHBOARD for monitoring purposes.
Comments
Post a Comment