我是靠谱客的博主 俊逸康乃馨,最近开发中收集的这篇文章主要介绍Hystrix-Dashboard-Turbine,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

参考文章:https://blog.csdn.net/trisonlu123/article/details/80100031

一、体验Hystrix-Dashboard

在consumer基础上进行更改

1、增加依赖

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

2、修改Main类

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
}

3、案例

启动server,producer,consumer

访问http://localhost:8003/hystrix


点击Monitor Stream


具体看效果可以访问下接口,看下监控效果,再停掉producer服务,再访问下接口,再看监控效果

具体监控描述如下图


二、体验Turbine

1、Hystrix-dashboard-turbine

①依赖配置

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.5.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-turbine</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-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

②application.properties

spring.application.name=hystrix-dashboard-turbine

server.port=8003
turbine.appConfig=node01,node02
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")

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

③Main类

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

2、consumer-node1,由consumer修改而来

application.properties

spring.application.name=node01

server.port=8001

feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
3、consumer-node2,由consumer修改而来

①application.properties

spring.application.name=node02

server.port=8002

feign.hystrix.enabled=true

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

②DemoRemote.java

@FeignClient(name = "spring-cloud-producer2", fallback = DemoRemoteHystrix.class)
public interface DemoRemote {
    @RequestMapping(value = "/demo")
    public String demo2(@RequestParam(value = "message") String message);
}

同时修改DemoRemoteHystrix.java和DemoController.java

4、案例

同时启动服务、consumer-node1、consumer-node2、hystrix-dashboard-turbine

①访问http://localhost:8000/,发现三个注册方


②访问http://localhost:8003/turbine.stream


发现监控一直存在,不断的调出:ping

③访问http://localhost:8003/hystrix


点击Monitor Stream


发现同时监控了两个consumer


最后

以上就是俊逸康乃馨为你收集整理的Hystrix-Dashboard-Turbine的全部内容,希望文章能够帮你解决Hystrix-Dashboard-Turbine所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部