Skip to content

Commit 87eb78d

Browse files
feat(nl2sql): improve httpclient timeout (alibaba#1333)
1 parent 9d0aa2d commit 87eb78d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

spring-ai-alibaba-nl2sql/chat/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
<version>${spring-ai.version}</version>
164164
</dependency>
165165

166+
<dependency>
167+
<groupId>org.springframework.boot</groupId>
168+
<artifactId>spring-boot-starter-webflux</artifactId>
169+
</dependency>
170+
166171
<dependency>
167172
<groupId>com.alibaba</groupId>
168173
<artifactId>dashscope-sdk-java</artifactId>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.cloud.ai.config;
18+
19+
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
20+
import org.springframework.boot.web.client.RestClientCustomizer;
21+
import org.springframework.context.annotation.Bean;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
24+
import org.springframework.web.reactive.function.client.WebClient;
25+
import reactor.netty.http.client.HttpClient;
26+
27+
import java.time.Duration;
28+
import java.time.temporal.ChronoUnit;
29+
30+
@Configuration
31+
public class RestConfiguration {
32+
33+
@Bean
34+
public RestClientCustomizer restClientCustomizer() {
35+
return restClientBuilder -> restClientBuilder
36+
.requestFactory(ClientHttpRequestFactoryBuilder.reactor().withCustomizer(factory -> {
37+
factory.setConnectTimeout(Duration.of(10, ChronoUnit.MINUTES));
38+
factory.setReadTimeout(Duration.of(10, ChronoUnit.MINUTES));
39+
}).build());
40+
}
41+
42+
@Bean
43+
public WebClient.Builder webClientBuilder() {
44+
45+
return WebClient.builder()
46+
.clientConnector(new ReactorClientHttpConnector(
47+
HttpClient.create().responseTimeout(Duration.of(600, ChronoUnit.SECONDS))));
48+
}
49+
50+
}

0 commit comments

Comments
 (0)