默认集群turbine及客户机设置
默认集群
turbine主机设置文件
properties
#应用名称
spring.application.name=hystrix-tuibine
#端口号
server.port=9698
#指定注册中心地址
eureka.client.service-url.defaultZone=http://127.0.0.1:1000/eureka
# 启用ip配置 这样在注册中心列表中看见的是以ip+端口呈现的
eureka.instance.prefer-ip-address=true
# 实例名称 最后呈现地址:ip:2000
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
#turbine配置
# 需要监控的应用名称,默认逗号隔开,内部使用Stringutils.commaDelimitedListToStringArray分割
turbine.app-config=hystrix-example
# 集群名称
turbine.cluster-name-expression="default"
# true 同一主机上的服务通过host和port的组合来进行区分,默认为true
# false 时 在本机才是时 监控中host集群数会为1了 因为本地host是一样的
turbine.combine-host-port=true
yml
server:
port: 10001
spring:
application:
name: service-turbine
eureka:
client:
serviceUrl:
defaultZone: http://localhost:10000/eureka/
instance:
# 启用ip配置 这样在注册中心列表中看见的是以ip+端口呈现的
prefer-ip-address: true
# 实例名称 最后呈现地址:ip:2000
instance-id: ${spring.cloud.client.ip-address}:${server.port}
# turbine配置
turbine:
# 需要监控的应用名称,默认逗号隔开,内部使用Stringutils.commaDelimitedListToStringArray分割
app-config: log-service,user-service
# false 时 在本机才是时 监控中host集群数会为1了 因为本地host是一样的
combine-host-port: true
# 集群名称
cluster-name-expression: new String('default')
启动类注解
# 若有问题可将@EnableHystrixDashboard单独拆出来启动
@SpringBootApplication
@EnableTurbine
@EnableDiscoveryClient
@EnableHystrixDashboard
pom依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
</dependencies>
turbine客户机设置
properties
spring.application.name=hystrix-example
server.port=8038
#指定注册中心地址
eureka.client.service-url.defaultZone=http://127.0.0.1:1000/eureka
# 启用ip配置 这样在注册中心列表中看见的是以ip+端口呈现的
eureka.instance.prefer-ip-address=true
# 实例名称 最后呈现地址:ip:2000
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
#开启feign 熔断
feign.hystrix.enabled=true
#开启监控端点
management.endpoints.web.exposure.include=hystrix.stream
yml
server:
port: 10003
eureka:
client:
serviceUrl:
defaultZone: http://localhost:10000/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
spring:
application:
name: log-service
datasource: #数据库配置
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://DESKTOP-SR0JFG7:3306/evenepay?characterEncoding=UTF-8&serverTimezone=GMT%2B8 #jdbc:mysql://rm-wz9y38u96q7ez6l87.mysql.rds.aliyuncs.com:3306/evenepay?characterEncoding=UTF-8
username: root
password: root
jpa:
database: mysql
hibernate:
ddl-auto: update
show-sql: true
management:
endpoints:
web:
exposure:
include: hystrix.stream
启动类注解
@SpringBootApplication
@EnableHystrix
@EnableDiscoveryClient
@EnableFeignClients
pom依赖
<dependencies>
<!-- 客户端依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- 引入 hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
自定义集群
turbine主机设置
properties
#应用名称
spring.application.name=hystrix-tuibine
#端口号
server.port=9698
#指定注册中心地址
eureka.client.service-url.defaultZone=http://127.0.0.1:1000/eureka
# 启用ip配置 这样在注册中心列表中看见的是以ip+端口呈现的
eureka.instance.prefer-ip-address=true
# 实例名称 最后呈现地址:ip:2000
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
#turbine配置
# 需要监控的应用名称,默认逗号隔开,内部使用Stringutils.commaDelimitedListToStringArray分割
turbine.app-config=hystrix-example
# 集群名称
turbine.cluster-name-expression=metadata['cluster']
# true 同一主机上的服务通过host和port的组合来进行区分,默认为true
# false 时 在本机才是时 监控中host集群数会为1了 因为本地host是一样的
turbine.combine-host-port=true
#指定聚合哪些集群,多个使用","分割,默认为 default
turbine.aggregator.clusterConfig=example
启动类注解
@SpringBootApplication
@EnableTurbine
@EnableDiscoveryClient
@EnableHystrixDashboard
pom
<dependencies>
<!-- turbine依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- eureka client依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
客户机设置
yml
eureka:
instance:
metadata-map:
cluster: example1
prefer-ip-address: true
instance-id: ${spring.cloud.version}:${server.port}
client:
service-url:
defaultZone: http://127.0.0.1:1000/eureka
spring:
application:
name: hystrix-example
server:
port: 8038
feign:
hystrix:
enabled: true
management:
endpoints:
web:
exposure:
include: hystrix.stream
启动类注解
@SpringBootApplication
@EnableHystrix
@EnableDiscoveryClient
@EnableFeignClients
pom
<dependencies>
<!-- 客户端依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- 引入 hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
打开App,阅读手记