Mar*_*pel 6 spring-boot spring-webflux
当使用 Spring Webflux 处理我的反应式 REST 端点时,我意识到,如果返回的内容Publisher在大约 30 秒内没有完成,它将被取消并返回响应代码 503。
我还没有在任何地方看到这种行为的记录。
REST 控制器示例:
package myapp.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import javax.servlet.http.HttpServletRequest;
import java.time.Duration;
@RestController
public class TestAlationIndexingRestController {
@RequestMapping(
value = "/test",
method = RequestMethod.GET
)
public Mono<String> test(HttpServletRequest request) {
return Mono.delay(Duration.ofMinutes(2)).thenReturn("Late");
}
}
Run Code Online (Sandbox Code Playgroud)
响应:503 无响应内容
我的问题:如何禁用此行为,或者至少增加超时?
注意:我尝试使用应用程序属性server.connection-timeout: -1,但server.connection-timeout: 15没有成功 - 请求在 30 秒多一点后仍然超时。
我正在使用 Spring Boot 依赖项(版本2.1.6-RELEASE):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
和
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.2.12.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我已经被这个问题困扰好几天了。最后我找到了解决方案。
首先在application.yml上添加异步超时配置
spring:
mvc:
async:
request-timeout: 60s
Run Code Online (Sandbox Code Playgroud)
如果以上配置不起作用。然后尝试在java代码中添加以下配置
@Configuration
@EnableWebMvc
public class ConfigurerAdapter implements WebMvcConfigurer {
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(3600000);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1551 次 |
| 最近记录: |