如何在没有 Reactive 的情况下使用 Spring Cloud Gateway?

how to use Spring Cloud Gateway without Reactive stuff?

我想使用 Spring Cloud Gateway 创建一个新项目,但我不想要所有的响应式功能。对我来说,如果其他微服务会阻塞 I/O 而不是 Reactive 就好了。

  1. 我该怎么做?
  2. 假设我将云网关实现为反应式的,而所有其他 MS 的实现为阻塞式的,这是一个好方法吗?那有什么缺点?

Spring 云网关建立在 spring webflux 和 netty 之上,这是无法更改的。

来自参考文档:

Spring Cloud Gateway is built on Spring Boot 2.x, Spring WebFlux, and Project Reactor. As a consequence, many of the familiar synchronous libraries (Spring Data and Spring Security, for example) and patterns you know may not apply when you use Spring Cloud Gateway. If you are unfamiliar with these projects, we suggest you begin by reading their documentation to familiarize yourself with some of the new concepts before working with Spring Cloud Gateway.

Spring Cloud Gateway requires the Netty runtime provided by Spring Boot and Spring Webflux. It does not work in a traditional Servlet Container or when built as a WAR.

Spring Cloud Reference Docs

非阻塞 IO 应用程序对阻塞 IO 应用程序进行网络调用是完全可以接受的。非阻塞 IO 应用程序仍然具有非阻塞 IO 的所有好处。它不会在等待网络调用对阻塞 IO 应用程序的响应时消耗资源,理论上应该消耗更少的资源并因此能够处理更多的并发调用。