關於SpringCloud中,使用 Hystrix的問題

  1. springCloud升級後。導致 HtystrixDashboard 默認的servlet請求路徑修改了
  2. 將業務的微服務使用 HtystrixDashboard 儀錶盤第一次監控時出現 Unable to connect to Command Metric Stream.

 

 

解決辦法: 這都是 業務微服務端更改。不是 htystrix

  1. 顯示的 聲明一個 servlet組
  2. 
    /**
         *此配置是為了服務監控而配置,與服務容錯本身無關,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;
        }
  3. 確認是否引入  actuator 的依賴
  4. <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  5. 一切準備完成後。 訪問 htystrix 檢測的地址 :  localhost:端口/htystrix.stream  . 進行業務訪問 。發現有 ping出現。說明此時客戶端沒有問題了
  6. 將此地址配入 htystrix
  7. 查看是否能正確訪問:
  8. 如果還是出現 Unable to connect to Command Metric Stream. 查看一下log日誌。 發現是   could’n allow list. 那麼在 htystrict端的 application.yml 文件中。配置host允許
    hystrix:
      dashboard:
        proxy-stream-allow-list: localhost