How to realize the Circuit Breaker Monitoring of Spring Cloud
This article introduces the relevant knowledge of "how to realize circuit breaker monitoring of Spring Cloud". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
I. Preparations
Start previous projects erurekaserver,config-server,eurekaclient1
II. Modification of project service-ribbon
1. Modify ServiceRibbonApplication.java
package wg;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.client.loadbalancer.LoadBalanced;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.cloud.netflix.hystrix.EnableHystrix;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;import org.springframework.context.annotation.Bean;import org.springframework.web.client.RestTemplate;import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;@SpringBootApplication@EnableEurekaClient@EnableDiscoveryClient@EnableHystrix@EnableCircuitBreaker@EnableHystrixDashboardpublic class ServiceRibbonApplication { public static void main(String[] args) { SpringApplication.run( ServiceRibbonApplication.class, args ); } @Bean @LoadBalanced RestTemplate restTemplate() { return new RestTemplate(); } @Bean public ServletRegistrationBean getServlet(){ HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/actuator/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; }}
2. Modify pom.xml
4.0.0 wg service-ribbon 0.0.1-SNAPSHOT jar service-ribbon http://maven.apache.org UTF-8 UTF-8 Greenwich.RELEASE 1.8 org.springframework.boot spring-boot-starter-parent 2.1.1.RELEASE org.springframework.cloud spring-cloud-starter-zipkin org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-starter-netflix-hystrix org.springframework.cloud spring-cloud-starter-netflix-hystrix-dashboard org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-netflix-ribbon junit junit test org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import
3. Start the project, visit http://localhost:8764/hello
4. Visit: http://localhost:8764/hystrix
Input:
OK, leave this page open.
5. Visit: http://localhost:8764/hello, come back to view the monitoring page:
6. Close eurekaclient1, visit http://localhost:8764/hello
View Monitoring Page:
"How to implement Spring Cloud circuit breaker monitoring" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!