1. 程式人生 > >Spring--Hystrix儀表盤Unable to connect to Command Metric Stream

Spring--Hystrix儀表盤Unable to connect to Command Metric Stream

Unable to connect to Command Metric Stream  這個是錯誤是連結不上,錯誤原因可能是缺少jar包或者沒有Enable相關服務。

針對ribbon實現斷路由監控

1.則pom中需要加入以下jar包

  1. <dependency>  
  2.             <groupId>org.springframework.cloud</groupId>  
  3.             <artifactId>spring-cloud-starter-hystrix</artifactId>  
  4.         </dependency>  
  5.         <dependency>  
  6.             <groupId>org.springframework.boot</groupId>  
  7.             <artifactId>spring-boot-starter-actuator</artifactId>  
  8.         </dependency>  
  9.         <dependency>  
  10.             <groupId>org.springframework.cloud</groupId>  
  11.             <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>  
  12.         </dependency>  
2.boot啟動程式啟動下面標籤對應的服務
@EnableHystrix
@EnableHystrixDashboard

3.對應的service上肯定要加上斷路由設定的
@HystrixCommand(fallbackMethod = "hiError")

針對fegin的實現斷路由監控

因為fegin中本身自帶斷路器的,所以跟ribbon的處理稍有不同

1.則pom中需要加入以下jar包,本身實現斷路處理不需要引入spring-cloud-starter-hystrix這個jar就可以實現,但是要加入監控則還是需要引入下面3個jar包

  1. <span style=
    "font-size:14px;"><dependency>  
  2.             <groupId>org.springframework.cloud</groupId>  
  3.             <artifactId>spring-cloud-starter-hystrix</artifactId>  
  4.         </dependency>  
  5.         <dependency>  
  6.             <groupId>org.springframework.boot</groupId>  
  7.             <artifactId>spring-boot-starter-actuator</artifactId>  
  8.         </dependency>  
  9.         <dependency>  
  10.             <groupId>org.springframework.cloud</groupId>  
  11.             <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>  
  12.         </dependency></span>  
2.boot啟動程式啟動下面標籤對應的服務(一定不能少@EnableCircuitBreaker,剛開始就是少這個報的unable to connect錯誤)
@EnableHystrixDashboard
@EnableCircuitBreaker

3.對應的service上肯定要加上斷路由設定的

@FeignClient(value = "service-hi" ,fallback = SchedualServiceHiHystric.class)
public interface SchedualServiceHi {
    @GetMapping("/hi")
    String sayHiFromClientOne(@RequestParam(value = "name") String name) ;
}