当前位置: 移动技术网 > IT编程>软件设计>架构 > SpringCloud-使用熔断器仪表盘监控熔断

SpringCloud-使用熔断器仪表盘监控熔断

2019年10月22日  | 移动技术网IT编程  | 我要评论

场景

springcloud-使用熔断器防止服务雪崩-ribbon和feign方式(附代码下载):

https://blog.csdn.net/badao_liumang_qizhi/article/details/102616697

在上面已经实现使用ribbon和feign的方式使用熔断器,但是如果服务一直在被熔断需要怎么解决。

所以这里使用熔断仪表盘监控熔断。

这里使用feign的方式使用监控。

注:

博客:

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

在pom.xml中加入依赖

<dependency>
    <groupid>org.springframework.cloud</groupid>
    <artifactid>spring-cloud-starter-netflix-hystrix-dashboard</artifactid>
</dependency>

 

然后在application中添加注解@enablehystrixdashboard

package com.badao.hello.spring.cloud.web.feign;

import org.springframework.boot.springapplication;
import org.springframework.boot.autoconfigure.springbootapplication;
import org.springframework.cloud.client.discovery.enablediscoveryclient;
import org.springframework.cloud.netflix.hystrix.dashboard.enablehystrixdashboard;
import org.springframework.cloud.openfeign.enablefeignclients;

@springbootapplication
@enablediscoveryclient
@enablefeignclients
@enablehystrixdashboard
public class webadminfeignapplication {
    public static void main(string[] args) {
        springapplication.run(webadminfeignapplication.class, args);
    }
}

 

 

创建hystrix.stream的servlet配置

在包下新建config包,在config包下新建config配置类

package com.badao.hello.spring.cloud.web.feign.config;

import com.netflix.hystrix.contrib.metrics.eventstream.hystrixmetricsstreamservlet;
import org.springframework.boot.web.servlet.servletregistrationbean;
import org.springframework.context.annotation.bean;
import org.springframework.context.annotation.configuration;

@configuration
public class hystrixdashboardconfiguration {
    @bean
    public servletregistrationbean getservlet() {
        hystrixmetricsstreamservlet streamservlet = new hystrixmetricsstreamservlet();
        servletregistrationbean registrationbean = new servletregistrationbean(streamservlet);
        registrationbean.setloadonstartup(1);
        registrationbean.addurlmappings("/hystrix.stream");
        registrationbean.setname("hystrixmetricsstreamservlet");
        return registrationbean;
    }
}

 

 

效果

打开浏览器,输入:

 

 

然后在url这里,输入上面在配置类中配置的url。

delay表示监控的间隔,默认是2秒钟。

title可以自己随意起。

 

 

然后点击monitor stream按钮。

 

 

此时我们多次触发熔断器,这里不启动服务提供者,使用服务消费者feign的方式去请求服务,使其触发熔断,打开浏览器输入:

http://localhost:8765/hi?message=hellofrign

然后再回到熔断仪表盘这里

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网