我正在尝试为我的API网关中的所有rquests添加全局超时。以下是我的路由bean:
@Configuration
public class DataserviceRoute {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("abc_service",
r -> r.path("/abc/**").uri("http://localhost:7010"))
.route("def_service",
r -> r.path("/def/**").uri("http://localhost:8085"))
.route("xyz_service",
r -> r.path("/xyz/**").uri("http://localhost:1800"))
.build();
}
}
如何为所有路线配置全局超时?
我找到了答案。我配置了下面的bean:
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/**")
.filters(f -> f.hystrix(config -> config.setName("appTimeout")))
.uri("http://localhost:8085")
.id("all_request"))
.build();
}
并在application.property
文件中添加了一个属性:
hystrix.command.appTimeout.execution.isolation.thread.timeoutInMilliseconds: 30000