Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Circuit Breaker Monitoring of Spring Cloud

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report