微服务架构之spring cloud turbine

在前面介绍了spring cloud hystrix及其hystrix dashboard,但都是对单个项目的监控,对于一个为项目而言,一定有不少微服务,一个一个去看很是的不方便,若是有一个能集中熔断器监控的地方就完美了,spring cloud turbine 就实现了这样的功能,这篇文章就来介绍spring cloud turbine。spring

(一) 版本说明express

a) Spring boot 2.0.6.RELEASE浏览器

b) Spring cloud Finchley.SR2app

c) Java version 1.8微服务

d) spring-cloud-starter-netflix-hystrix 2.0.2.RELEASEfetch

e) spring-cloud-starter-netflix-hystrix-dashboard 2.0.2.RELEASEurl

f) spring-cloud-starter-netflix-turbine 2.0.2.RELEASEspa

(二) 项目配置code

1. 项目设置server

a) POM设置

<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>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-netflix-turbine</artifactId>

</dependency>

b) application.yml配置文件

eureka:

datacenter: ctm

environment: dev

instance:

hostname: 192.168.1.78

prefer-ip-address: true

ip-address: 192.168.1.129

lease-renewal-interval-in-seconds: 10

lease-expiration-duration-in-seconds: 30

instance-id: ${eureka.instance.ip-address}:${server.port}

client:

service-url:

defaultZone: http://${eureka.instance.hostname}:1001/eureka/,http://${eureka.instance.hostname}:1002/eureka/,http://${eureka.instance.hostname}:1003/eureka/

fetch-registry: true

register-with-eureka: true

healthcheck:

enabled: true

turbine:

aggregator:

cluster-config: default

app-config: clientservice,callbackservice

cluster-name-expression: new String("default")

c) 主要参数说明

i. eureka.instance.prefer-ip-address 使用IP显示注册信息

ii. eureka.instance.ip-address 实例IP地址,

iii. eureka.instance.instance-id 自定义实例id,服务之间调用就是使用该配置,多个实例必须保证惟一性

iv. eureka.client.service-url.defaultZone 注册中心地址

v. turbine.app-config 设置要汇集的服务名称,这里是指注册的服务名字

2. 项目运行

a) 运行要监控的服务

i. 为了演示汇集的效果,这里运行了2个服务者实例后,会在服务中心看到以下效果

clip_image002

b) 运行

i. 运行turbine项目,以下图所示

clip_image004

c) 在浏览器中输入消费者地址服务地址,便可看到以下效果

clip_image006

在看板地址中输入http://localhost:1251/turbine.stream,而后点击Monitor Stream 按钮,便可看到熔断器监控,若是没有数据显示,能够用任何客户端调用几回API,便可看到聚合后的效果。

clip_image008

  这样spring cloud turbine就介绍完了,若是在开发中遇到问题,也能够留言共同探讨共同进步。