资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么实现SpringCloud的断路器监控

本篇内容介绍了“怎么实现Spring Cloud的断路器监控”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

成都创新互联,为您提供成都网站建设成都网站制作、网站营销推广、网站开发设计,对服务成都木屋等多个行业拥有丰富的网站建设及推广经验。成都创新互联网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!

一、准备工作

启动以前的项目 erurekaserver,config-server,eurekaclient1

二、修改项目service-ribbon

1、修改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
@EnableHystrixDashboard
public 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、修改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、启动项目,访问:http://localhost:8764/hello

怎么实现Spring Cloud的断路器监控

4、访问:http://localhost:8764/hystrix

输入:怎么实现Spring Cloud的断路器监控

确定,留着这个页面打开状态。

怎么实现Spring Cloud的断路器监控

5、 访问:http://localhost:8764/hello,回来查看监控页:

怎么实现Spring Cloud的断路器监控

6、关闭 eurekaclient1  ,访问 :http://localhost:8764/hello

怎么实现Spring Cloud的断路器监控

查看监控页面:

怎么实现Spring Cloud的断路器监控

“怎么实现Spring Cloud的断路器监控”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


当前文章:怎么实现SpringCloud的断路器监控
分享链接:http://cdkjz.cn/article/ijosch.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220