1. Health Indicator 健康指示器
连接的断路器的状态也暴露在调用应用程序的/health下,如下例所示:
{
"hystrix": {
"openCircuitBreakers": [
"StoreIntegration::getStoresByLocationLink"
],
"status": "CIRCUIT_OPEN"
},
"status": "UP"
}
下面我演示自己的实验:
项目启动:
1.microservice-discovery-eureka
security:
basic:
enabled: true
user:
name: user
password: password123
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://user:password123@localhost:8761/eureka
2.microservice-provider-user
server:
port: 7900
spring:
jpa:
generate-ddl: false
show-sql: true
hibernate:
ddl-auto: none
datasource:
platform: h2
schema: classpath:schema.sql
data: classpath:data.sql
application:
name: microservice-provider-user
logging:
level:
root: INFO
org.hibernate: INFO
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
org.hibernate.type.descriptor.sql.BasicExtractor: TRACE
com.itmuch: DEBUG
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
metadata-map:
zone: ABC # eureka可以理解的元数据
lilizhou: BBC # 不会影响客户端行为
lease-renewal-interval-in-seconds: 5
3. microservice-consumer-movie-ribbon-with-hystrix
spring:
application:
name: microservice-consumer-movie-ribbon-with-hystrix
server:
port: 8010
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka
instance:
prefer-ip-address: true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
请求地址:http://localhost:8010/health
请求:http://localhost:8010/movie/1
停掉用户微服务(microservice-provider-user),模拟用户微服务宕掉的情况
连续请求:http://localhost:8010/movie/1
返回如下结果:
再次请求http://localhost:8010/health如下结果:断路器打开
2. Hystrix Metrics Stream
要启用Hystrix metrics流,需要包含对spring-boot-start -actuator的依赖,并设置management.endpoints.web.exposure.include: hystrix.stream。暴露/actuator/hystrix.stream下,依赖如下:(不加项目也
hystrix.stream其实是监控API情况,如下:
日志不停打出,也很难读,所用可用 Hystrix Dashboard做监控