如何解决为什么必须在 Gateway&Hystrix 的回退函数上扩展 HystrixCommand 或使用 @HystrixCommand?
为什么必须在 Gateway&Hystrix 的回退函数上扩展 HystrixCommand 或使用 @HystrixCommand ? 这个网址中的代码: https://github.com/shzxj/gateway-hystrix.git 我想在 yml 中使用动态路由。 我应该怎么办 ?谁能帮帮我?
控制器代码:
@GetMapping("/fallback")
public String fallback() {
return "fallback";
}
@GetMapping("/test")
public String test() {
try {
sleep(2000L);
} catch (InterruptedException e) {
e.printstacktrace();
}
return "test";
}
开始课程代码:
@SpringBootApplication
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class,args);
}
}
应用程序.yml
server:
port: 8000
logging:
level:
root: INFO
spring:
application:
name: api-gateway
cloud:
gateway:
default-filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallback
routes:
- id: api-gateway
uri: http://localhost:8000
order: 0
predicates:
- Path=/gateway/**
filters:
- StripPrefix=1
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallback
filters:
- name: Hystrix
args:
name : default
fallbackUri: forward:/fallback
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 100
fallbackcmd:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 100
circuitBreaker:
forceOpen: true
ribbon:
ReadTimeout: 100
ConnectTimeout: 100
当请求不存在的路径“/test_error”时,回退正在工作。 请求路径“/test”时回退不起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。