问题描述
在来自 youtube 的 tutorial 中,作者使用 Spring Cloud Gateway、Hystrix、Netflix,并使用 application.yml 配置路由,但是当我尝试从端点发送数据我只是挂在Hystrix仪表板上“加载...”,在教程中效果很好...
hystrix.stream 运行良好,把他放在 Histrix 仪表板中,只显示“正在加载”
我尝试了另一个教程,但问题仍然存在!
Maven 依赖
spring-cloud-starter-netflix-eureka-client
spring-cloud-starter-config
lombok
spring-boot-starter-data-jpa
spring-boot-starter-web
spring-cloud-starter-hystrix:2.7.3.RELEASE
<spring-cloud.version>Hoxton.SR10</spring-cloud.version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
application.yml
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- id: USER-SERVICE
uri: lb://USER-SERVICE
predicates:
- Path=/user/**
filters:
- name: CircuitBreaker
args:
name: USER-SERVICE
fallbackuri: forward:/userServiceFallBack
- id: DEPARTMENT-SERVICE
uri: lb://DEPARTMENT-SERVICE
predicates:
- Path=/department/**
filters:
- name: CircuitBreaker
args:
name: DEPARTMENT-SERVICE
fallbackuri: forward:/departmentServiceFallBack
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
如果使用@EnableCircuitBreaker 运行良好,问题是使用application.yml 来配置spring cloud 路由?
解决方法
解决方案很简单,API-GATEWAY,其中 hystrix.stream 用于端口 8789 和 USER-SERVICE 在端口 9001 上,因此您需要将 API-GATEWAY 端口与用户端点一起使用来处理指标。
API-GATEWAY port: 8789
USER-SERVICE port: 9001
问题:
API-GATEWAY - http://localhost:8789/acturator/hystrix.stream
USER-SERVICE save user - http://localhost:9001/user/
解决方案:
API-GATEWAY - http://localhost:8789/acturator/hystrix.stream
USER-SERVICE save user - http://localhost:8789/user/
指标现在运行良好,Hystrix 仪表板可以正常运行。