当前位置: 代码迷 >> 综合 >> Spring Cloud 最新版使用 Hystrix DashBoard 问题解决
  详细解决方案

Spring Cloud 最新版使用 Hystrix DashBoard 问题解决

热度:127   发布时间:2023-10-18 19:09:19.0

Hystrix报错:Unable to connect to Command Metric Stream

检查了pom文件 和启动类的注释都没有问题 后来发现是springboot版本的问题,版本1.5之前是不需要进行配置的 但是2.x之后是需要对Hystrix进行配置的。

在hystrix-service的启动类中添加

/***此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑*ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",*只要在自己的项目里配置上下面的servlet就可以了*/@Beanpublic ServletRegistrationBean getServlet() {HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);registrationBean.setLoadOnStartup(1);registrationBean.addUrlMappings("/hystrix.stream");registrationBean.setName("HystrixMetricsStreamServlet");return registrationBean;}

只在这个启动类中添加以上代码还不行,在hystrix-service模块色yml文件中添加

management:endpoints:web:exposure:include: 'hystrix.stream'

添加以上代码后发现还是报错:控制台报错 EventSource's response has a MIME type ("text/plain") that is not "text/event-stream". Aborting the connection.

在网上各种搜索最后发现需要在Hystrix-dashboard模块的yml文件中添加如下代码:

hystrix:dashboard:proxy-stream-allow-list: "localhost"

Spring Cloud 最新版使用 Hystrix DashBoard 问题解决

 

 

 

  相关解决方案