9. Hystrix 指标聚合(使用 Turbine 和 Consul)

Turbine(由Spring Cloud Netflix项目提供)聚合多个实例的Hystrix指标流,从而使仪表板能够显示汇总视图。Turbine使用DiscoveryClient接口来查找相关实例。若要将Turbine与Spring Cloud Consul配合使用,请按照以下示例中的方式配置Turbine应用程序:spring-doc.cadn.net.cn

pom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>

请注意,Turbine 依赖项不是Starters。turbine Starters包含对 Netflix Eureka 的支持。spring-doc.cadn.net.cn

application.yml
spring.application.name: turbine
applications: consulhystrixclient
turbine:
  aggregator:
    clusterConfig: ${applications}
  appConfig: ${applications}

clusterConfig 项和 appConfig 项必须匹配,因此将服务 ID 的逗号分隔列表放入一个独立的配置属性中会很有用。spring-doc.cadn.net.cn

Turbine.java
@EnableTurbine
@SpringBootApplication
public class Turbine {
    public static void main(String[] args) {
        SpringApplication.run(DemoturbinecommonsApplication.class, args);
    }
}