Hystrix-Dashboard报错踩坑

spring2.0之后 Hystrix-Dashboard 一直出现 Unable to connect to Command Metric Stream解决办法

  • Hystrix-Dashboard服务
    • 引入相关依赖
    • 配置yml文件
    • 主启动类
  • 被监控的微服务
    • 相关依赖
    • 配置yml文件
    • 主启动类

Hystrix-Dashboard服务

引入相关依赖


        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboardartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-hystrixartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>

配置yml文件

#端口号,自己定义的
server:
  port: 9001

#一定要加,不然还是会出现Unable to connect to Command Metric Stream,"*",可以换成其他内容
management:
  endpoints:
    web:
      exposure:
        include: '*'

主启动类

//加上该注解,开启图形化Dashboard
@EnableHystrixDashboard

被监控的微服务

相关依赖

<dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>

配置yml文件

#端口号
server:
  port: 8001
spring:
  application:
    name: cloud-provider-hystrix-payment

#注册进eureka,你可以用其他服务注册中心(Zookeeper,Consul,Nacos)
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka

主启动类

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class PaymentHystrixMain8001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentHystrixMain8001.class,args);
    }
//spring2.0之后一定要加这个
    @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;
    }

}

Hystrix-Dashboard报错踩坑_第1张图片

文章来源。1


  1. 尚硅谷周阳老师springcloud第二季Hystrix-Dashboard以及整合网上好多方法,找出适合我的 ↩︎

你可能感兴趣的:(微服务)