我正在spring-cloud-gateway
项目中工作。我需要配置全局超时/应用程序级别超时和api特定超时。以下是我的下游apis:
@RestController
public class TestController {
// Should have global time out
@GetMapping("/global")
public Mono<ResponseEntity> testGlobalTimeOut(
@RequestHeader(name = "cId") UUID cId,
@RequestParam(name = "someNumber", required = false) Number someNumber) {
// Map<String, Object> map = populate Some Map Logic
return Mono.just(new ResponseEntity(map, HttpStatus.OK));
}
// Should have application level time out
@GetMapping("/appname/count")
public Mono<ResponseEntity> testApplicationTimeOut_1(
@RequestHeader(name = "cId") UUID cId,
@RequestParam(name = "someNumber", required = false) Number someNumber) {
// Map<String, Object> map = populate Some Map Logic
return Mono.just(new ResponseEntity(map, HttpStatus.OK));
}
// Should have application level time out
@GetMapping("/appname/posts")
public Mono<ResponseEntity> testApplicationTimeOut_2(
@RequestHeader(name = "cId") UUID cId,
@RequestParam(name = "someNumber", required = false) Number someNumber) {
// Map<String, Object> map = populate Some Map Logic
return Mono.just(new ResponseEntity(map, HttpStatus.OK));
}
// Should have api level time out
@GetMapping("/appname/posts/{postId}")
public Mono<ResponseEntity> getAPITimeOutWithPathVariable(
@RequestHeader(name = "cId") UUID cId,
@PathVariable(name = "postId") String postId) {
// Map<String, Object> map = populate Some Map Logic
return Mono.just(new ResponseEntity(map, HttpStatus.OK));
}
}
此apis作为下游服务运行。以下是我gateway-application
中所有这些api的路线配置:
# ============ Application Timeout =============
- id: application_timeout_route_1
uri: http://localhost/appname/count
predicates:
- Path=/withapplicationtimeout1**
filters:
- Hystrix=appTimeOut
- id: application_timeout_route_2
uri: http://localhost/appname/posts
predicates:
- Path=/withapplicationtimeout2**
filters:
- Hystrix=appTimeOut
# ============ API Level Timeout ===========
- id: api_timeout_route
uri: http://localhost
predicates:
- Path=/withapitimeout/**
filters:
- Hystrix=apiTimeOut
- RewritePath=/withapitimeout/(?<segment>.*), /appname/posts/$\{segment}
# Global Timeout Configuration
#hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 30000
# Application Level Timeout Configuration
hystrix.command.appTimeOut.execution.isolation.thread.timeoutInMilliseconds: 30000
# API Level Timeout Configuration
hystrix.command.apiTimeOut.execution.isolation.thread.timeoutInMilliseconds: 15000
现在应用程序级别超时和api级别超时工作正常,但我没有任何方法来定义全局超时过滤器。目前尚未提供相同的文档:
任何想法如何做到这一点?