当前位置: 移动技术网 > IT编程>开发语言>Java > 微服务熔断限流Hystrix之流聚合

微服务熔断限流Hystrix之流聚合

2019年05月09日  | 移动技术网IT编程  | 我要评论

简介

上一篇介绍了 hystrix dashboard 监控单体应用的例子,在生产环境中,监控的应用往往是一个集群,我们需要将每个实例的监控信息聚合起来分析,这就用到了 turbine 工具。turbine有一个重要的功能就是汇聚监控信息,并将汇聚到的监控信息提供给hystrix dashboard来集中展示和监控。

流程

实验

工程说明

工程名 端口 作用
eureka-server 8761 注册中心
service-hi 8762 服务提供者
service-consumer 8763 服务消费者
service-turbine 8765 turbine服务

核心代码

eureka-server 、service-hi、service-consumer 工程代码与上一节 微服务熔断限流hystrix之dashboard 相同,下面是 service-turbine 工程的核心代码。

pom.xml

<dependency>
    <groupid>org.springframework.cloud</groupid>
    <artifactid>spring-cloud-starter-netflix-eureka-client</artifactid>
</dependency>
<dependency>
    <groupid>org.springframework.cloud</groupid>
    <artifactid>spring-cloud-starter-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-netflix-hystrix</artifactid>
</dependency>
<dependency>
    <groupid>org.springframework.cloud</groupid>
    <artifactid>spring-cloud-starter-netflix-hystrix-dashboard</artifactid>
</dependency>

application.yml

server:
  port: 8765

spring:
  application:
    name: service-turbine
eureka:
  client:
    service-url:
      defaultzone: http://localhost:8761/eureka/

turbine:
  app-config: service-consumer
  cluster-name-expression: new string("default")
  combine-host-port: true

参数说明:

  • turbine.app-config:指定要监控的应用名
  • turbine.cluster-name-expression:指定集群的名字
  • turbine.combine-host-port:表示同一主机上的服务通过host和port的组合来进行区分,默认情况下是使用host来区分,这样会使本地调试有问题

启动类

@springbootapplication
@enableeurekaclient
@enablehystrixdashboard
@enableturbine
public class serviceturbineapplication {

    public static void main(string[] args) {
        springapplication.run( serviceturbineapplication.class, args );
    }

}

模拟多实例

启动多个 service-consumer 工程,来模拟多实例,可以通过命令java -jar service-consumer.jar --server.port=xxxx 来实现。

为了方便,在编辑器中实现启动工程。但 idea 不支持单个应用的多次启动, 需要开启并行启动:

选择 “edit configurations...”

勾选 “allow running in parallel”

测试

启动工程,访问 http//localhost:8763/hi , http//localhost:8764/hi , http//localhost:8763/oh , http//localhost:8764/oh,来产生测试数据。

访问 http://www.lhsxpumps.com/_localhost:8765/hystrix ,

输入监控流地址 http://localhost:8765/turbine.stream ,点击 monitor stream 进入监控页面

可以看到聚合了两个实例的 hystrix dashbord 数据。

源码

https://github.com/gf-huanchupk/springcloudlearning/tree/master/chapter18




欢迎扫码或微信搜索公众号《程序员果果》关注我,关注有惊喜~

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网