当前位置: 首页 > 工具软件 > Hystrix > 使用案例 >

hystrix-dashboard

萧业
2023-12-01

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

使用步骤

1.引入依赖

代码如下(示例):

        <!--hystrix-dashboard-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

2.启动器(记得配置server端口)

代码如下(示例):

package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard
public class DeptConsumerHystrixDashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumerHystrixDashboard_9001.class, args);
    }
}

3.被监听的服务提供者所需的配置

1.必须有actuator依赖(示例):

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

2.注册servlet(示例):

package com;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.mybatis.spring.annotation.MapperScan;
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.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan("com.dao")
@EnableEurekaClient
@EnableDiscoveryClient//服务发现
@EnableCircuitBreaker//添加对熔断的支持
public class DeptProviderHystrix_8001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptProviderHystrix_8001.class, args);
    }

    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        ServletRegistrationBean regist = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        regist.addUrlMappings("/hystrix.stream");
        return regist;
    }
}

总结

经过个人测试,被监听的服务提供者还需提供对服务熔断的支持
还有hystrix-dashboard依赖里面有web,不需要额外引入
一只勤奋的菜鸡

 类似资料: