关于SpringCloud中,使用 Hystrix的问题
- springCloud升级后。导致 HtystrixDashboard 默认的servlet请求路径修改了
- 将业务的微服务使用 HtystrixDashboard 仪表盘第一次监控时出现 Unable to connect to Command Metric Stream.
解决办法: 这都是 业务微服务端更改。不是 htystrix
- 显示的 声明一个 servlet组
-
/** *此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑 *ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream", *只要在自己的项目里配置上下面的servlet就可以了 * cloud更改前的路径应该是 /actuator/hystrix */ @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; } - 确认是否引入 actuator 的依赖
-
org.springframework.boot spring-boot-starter-actuator - 一切准备完成后。 访问 htystrix 检测的地址 : localhost:端口/htystrix.stream . 进行业务访问 。发现有 ping出现。说明此时客户端没有问题了
- 将此地址配入 htystrix
- 查看是否能正确访问:
- 如果还是出现 Unable to connect to Command Metric Stream. 查看一下log日志。 发现是 could'n allow list. 那么在 htystrict端的 application.yml 文件中。配置host允许
hystrix: dashboard: proxy-stream-allow-list: localhost
| Arabic | Hebrew | Polish |
| Bulgarian | Hindi | Portuguese |
| Catalan | Hmong Daw | Romanian |
| Chinese Simplified | Hungarian | Russian |
| Chinese Traditional | Indonesian | Slovak |
| Czech | Italian | Slovenian |
| Danish | Japanese | Spanish |
| Dutch | Klingon | Swedish |
| English | Korean | Thai |
| Estonian | Latvian | Turkish |
| Finnish | Lithuanian | Ukrainian |
| French | Malay | Urdu |
| German | Maltese | Vietnamese |
| Greek | Norwegian | Welsh |
| Haitian Creole | Persian |
/**
*此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑
*ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
*只要在自己的项目里配置上下面的servlet就可以了
* cloud更改前的路径应该是 /actuator/hystrix.stream
*/
@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;
}