Commit af9e4fac authored by zhouwei's avatar zhouwei

增强超时处理逻辑

parent 1c983936
......@@ -12,10 +12,10 @@ import org.springframework.context.annotation.Configuration;
public class AppConfig {
@Value("${alert.host}")
String alertHost;
@Value("${gateway.request.timeout:50000}")
private int requestTimeout;
@Value("${gateway.request.timeout:30000}")
private Integer requestTimeout;
public int getRequestTimeout() {
public Integer getRequestTimeout() {
return requestTimeout;
}
......
......@@ -265,11 +265,17 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
log.info("request id:{} Starting {} request to: {}",exchange.getAttributes().get(REQUEST_ID), isSourceRequest ? "source" : "target", fullUrl);
long startTime = System.currentTimeMillis();
Integer requestTimeout = appConfig.getRequestTimeout();
// 创建 WebClient 请求
if(!isSourceRequest){
//第二次请求兜底增长时间
requestTimeout = requestTimeout + 50000;
}
WebClient client = webClientBuilder.clone()
.clientConnector(new ReactorClientHttpConnector(HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, appConfig.getRequestTimeout())
.responseTimeout(Duration.ofMillis(appConfig.getRequestTimeout()))))
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, requestTimeout)
.responseTimeout(Duration.ofMillis(requestTimeout))))
.build();
WebClient.RequestBodySpec requestBodySpec = client
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment