How to realize Circuit Breaker Monitoring by Spring Cloud
This article mainly shows you how to realize circuit breaker monitoring in Spring Cloud. The content is simple and easy to understand. It is clearly organized. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "How to realize circuit breaker monitoring in Spring Cloud".
Introduction to Hystrix Dashboard
In microservice architecture, for example, to ensure the availability of programs and prevent program errors from causing network congestion, circuit breaker model appears. The condition of the circuit breaker reflects the availability and robustness of a program, and it is an important indicator. Hystrix Dashboard is a component of the breaker status that provides data monitoring and a friendly graphical interface.
II. Preparations
The engineering chestnut of this article is derived from the chestnut of the first article and modified on its basis.
3. Start to transform service-hi
In the POM project file introduce the corresponding dependencies:
org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-starter-hystrix-dashboard org.springframework.cloud spring-cloud-starter-hystrix
Of these, these three dependencies are necessary and indispensable.
At the entry of the program ServiceHiApplication class, add @EnableHystrix annotation to open the circuit breaker, this is necessary, and you need to declare the disconnection point HystrixCommand in the program; add @EnableHystrixDashboard annotation to open HystrixDashboard
@SpringBootApplication@EnableEurekaClient@RestController@EnableHystrix@EnableHystrixDashboardpublic class ServiceHiApplication { public static void main(String[] args) { SpringApplication.run(ServiceHiApplication.class, args); } @Value("${server.port}") String port; @RequestMapping("/hi") @HystrixCommand(fallbackMethod = "hiError") public String home(@RequestParam String name) { return "hi "+name+",i am from port:" +port; } public String hiError(String name) { return "hi,"+name+",sorry,error! "; }}
Run the program: open eureka-server and service-hi in turn.
IV. Graphic display of Hystrix Dashboard
Open http://localhost:8762/hystrix.stream and you can see some specific data:
Open locahost:8762/hystrix to see the following interface:
Enter locahost:8762/hystrix.stream, 2000, miya in turn on the interface
The point is certain.
In another window type: http://localhost:8762/hi? name=forezp
Refresh hystrix.stream and you'll see a nice graphical interface:
The above is "Spring Cloud how to achieve circuit breaker monitoring" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!