Spring webflux阻止了另一个请求

问题描述 投票:0回答:1

我正在学习Spring webflux,面临一个不理解的情况。

Spring版本=2.2.4.RELEASEMy电脑有4个核心。

我的类。

@RestController
@RequestMapping("rest/v1/")
public class RootController {

    private final WebClient webClient =
            WebClient.create("http://localhost:8081");

    @GetMapping("/booking")
    public Mono book() {
        return Mono.just("A");
    }

    @GetMapping("/sleep")
    public Mono<String> sleep(@RequestParam("time") long time) throws InterruptedException {
        System.out.printf("Thread name is %s, date is %s. \n", Thread.currentThread().getName(), new Date());
        String uri = "/rest/v1/sleep?time=" + time;
        String uuid = UUID.randomUUID().toString();

        System.out.println(">>>>>>>>>>>>" + uuid);
        Mono<String> stringMono = webClient.get().uri(uri)
                .retrieve()
                .bodyToMono(String.class);
        System.out.printf("Finish -> Thread name is %s, date is %s. \n", Thread.currentThread().getName(), new Date());
        return stringMono;
    }
}

我的机器上有另一个应用程序,运行在8081端口上,这个终端只在param接收到的一段时间内睡觉。

我们的目标是测试webflux在调用慢速端点时的行为。

我正在执行这样一个请求。

http:/localhost:8082restv1sleep?time=20000。

在这种情况下,响应将需要20s。

当我在这期间执行另一个请求时,控制器不处理该请求,而是一直等待该请求完成(20s)。

在等待网络调用时,Spring是否应该处理另一个请求?

这是日志。

Thread name is reactor-http-epoll-3, date is Sat May 16 19:06:54 BRT 2020. 
>>>>>>>>>>>>22b36a46-e36b-4104-981a-e132483a334e
Finish -> Thread name is reactor-http-epoll-3, date is Sat May 16 19:06:54 BRT 2020. 
Thread name is reactor-http-epoll-3, date is Sat May 16 19:07:14 BRT 2020. 
>>>>>>>>>>>>076a0eec-3bb1-485a-ab88-9b11c6b9a5bd
Finish -> Thread name is reactor-http-epoll-3, date is Sat May 16 19:07:14 BRT 2020. 
spring spring-webflux
1个回答
0
投票

这个问题是chrome的问题,它把我的请求排了队,就像 "Martin Tarjányi "在他的评论中说的那样。

你是否从Chrome浏览器中找到了你的端点?我经历了类似的问题,不知道的原因,虽然。在我的记忆中,无论是在Firefox还是Edge中都很好用。你也可以从其他应用中以编程方式调用它。编辑:stackoverflow.coma532367416051176

非常感谢 @Martin Tarjányi

使用其他客户端或更改参数的请求效果良好。同样的资源chrome会排队请求。

© www.soinside.com 2019 - 2024. All rights reserved.