hystrix 添加turbine

1.创建turbine项目,修改pom.xml文件

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>

2.创建main函数

package com.imooc.springcloud;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@EnableDiscoveryClient
@EnableHystrix
@EnableCircuitBreaker
@EnableTurbine
@EnableAutoConfiguration
public class TurbineApplication {
    public static void main(String[] args) {
        new SpringApplicationBuilder(TurbineApplication.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    }
}

3.添加配置

3.1修改turbine的application.propertise
spring.application.name=hystrix-turbine
server.port=52000
management.port=52001

eureka.client.serviceUrl.defaultZone=http://localhost:20000/eureka/

# 指定了需要监控的服务名
turbine.app-config=hystrix-consumer
turbine.cluster-name-expression="default"

# 将端口和hostname 作为区分不同服务的条件
turbine.combine-host-port=true
turbine.instanceUrlSuffix.default=actuator/hystrix.stream
turbine.aggregator.clusterConfig=default

3.2 在原来用hystrix的服务中配置文件中添加下面配置

# actuator 暴露接口
management.security.enabled=false
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

4.开启Eureka,服务提供者,服务消费者

posted @ 2020-12-16 08:35  橙宝技术  阅读(82)  评论(0编辑  收藏  举报