首先,我是基于上一個例子ZooKeeper實作的服務注冊與發現
然後不知道是不是ZK的問題,而不是使用Eureka的問題,導緻通路/hystrix.stream時一緻報錯:Unable to connect to Command Metric Stream,此方法在網上沒能找到解決方案。
如果是以Eureka來搭建的,內建很簡單,隻要在服務消費者上引入依賴即可
POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
然後在main方法入口的Class上加入以下注解:
@EnableCircuitBreaker
@EnableHystrix
@EnableHystrixDashboard
最後通路/hystrix
輸入位址和Title
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsISPrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdsATOfd3bkFGazxCMx8VesATMfhHLlN3XnxCMwEzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5SM3UDN2QjN5MzY5YDZiJWZlJGMidTM2AzNhJjNlVDZi9CXxAzLchDMxIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjL1M3Lc9CX6MHc0RHaiojIsJye.png)
即可看見監控的資料: