如何解决Spring Cloud Gateway 路由不工作,Hystrix Dashboard 崩溃加载
在来自 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 仪表板可以正常运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。