how to use Spring Cloud Gateway without Reactive stuff?
Asked Answered
J

3

7

I want to create a new project with Spring Cloud Gateway but I don't want all the reactive functionality. for me, it will be fine if the other microservice will be blocking I/O and not Reactive.

  1. how can I do that?
  2. let's say I'm implementing cloud gateway as reactive and all the other MS's as blocking, its a good approach? what are the cons of that?
Johnsonian answered 21/1, 2021 at 8:52 Comment(0)
F
3

Spring cloud gateway is built on top of spring webflux and netty and this cannot be changed.

From The Spring Cloud Reference Docs:

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.

It is perfectly acceptable for a non-blocking IO application to make network calls to a blocking IO application. The non-blocking IO app will still have all of the benefits of having a non-blocking IO. It will not consume resources while waiting for responses from network calls to blocking IO applications and in theory should consume less resources and be able to handle more concurrent calls as a result.

Furry answered 21/1, 2021 at 11:21 Comment(4)
Thanks for your answer, Michael. so if I understood you well - the gateway will not wait for the response for the other I/O Blocking MS, am I right?Johnsonian
so if I understood you well - the gateway will not wait for the response for the other I/O Blocking MS, am I right?Johnsonian
spring cloud gateway will wait for a response though it will not blocking any resource (ie thread) while waiting on the response. It might be useful to read up on the reactor pattern and how it differs from the thread per request model found in spring mvc. dzone.com/articles/…Furry
With the advent of virtual threads, there is also MVC Spring gateway that doesn't use reactive stack: docs.spring.io/spring-cloud-gateway/reference/…Sporogenesis
M
0

You cannot change the reactive nature of gateway but whats in control is this.

Create 2 boot applications one is reactive gateway amd other normal spring boot with web. Register your routes on gateway. This was you can setup gateway as first layer and all your apis hosted from non reactive web application from other boot project.

Midrash answered 30/7, 2023 at 22:15 Comment(0)
B
-3

Add this :

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

then set :

spring.main.web-application-type=reactive

in application.properties

Bly answered 21/6, 2022 at 7:23 Comment(1)
The question was how to use the library without reactiveAugend

© 2022 - 2025 — McMap. All rights reserved.