栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringCloud

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringCloud

一.导入依赖

1.创建Dashboard模块并导入依赖

        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix
            2.2.10.RELEASE
        
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
            2.2.10.RELEASE
        

2.为被监控的服务提供端导入依赖

        
        
            org.springframework.boot
            spring-boot-starter-actuator
            2.6.7
        
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
            2.2.10.RELEASE
        
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix
            2.2.10.RELEASE
        
二.代码部分

1.编写Dashboard模块主启动类

注:为主启动类添加@EnableHystrixDashboard注解以开启Dashboard监控页面

@SpringBootApplication
@EnableHystrixDashboard//开启Dashboard监控页面
public class DeptConsumerDashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumerDashboard_9001.class);
    }
}

2.为服务提供端主启动类添加bean

    //配置收集流数据的servlet
    //访问 http://localhost:8001/actuator/hystrix.stream
    @Bean
    public ServletRegistrationBean SRB(){
        ServletRegistrationBean servletRB = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
//        servletRB.setName("HystrixMetricsStreamServlet");//名字
//        servletRB.setLoadOnStartup(1);//启动优先级
        servletRB.addUrlMappings("/actuator/hystrix.stream");
        return servletRB;
    }
三.配置yml文件

配置Dashboard模块的yml文件 

server:
  port: 9001

hystrix:
  dashboard:
    proxy-stream-allow-list: "localhost" #允许Dashboard监控的流的ip地址
运行效果

访问http://localhost:9001/hystrix

在该页面访问http://localhost:8001/actuator/hystrix.stream

注:需要先访问一次启用了熔断机制的服务,否则将一直loading,无法获取数据

进行多次错误请求,可以看到此时熔断机制已经开启

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/924804.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号