Die reaktive Grundlage verstehen
Entdecken Sie, warum Spring Cloud Gateway auf einem nicht blockierenden reaktiven Stack basiert und was das für den Weg von Anfragen durch das Gateway bedeutet.
Die reaktive Grundlage verstehen ist eine kostenlose API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
A Different Kind of Server
Unlike a traditional Spring MVC app, Spring Cloud Gateway runs on Spring WebFlux and Project Reactor. It uses a non-blocking, event-loop server (Netty) instead of one thread per request.
This design lets the gateway handle thousands of concurrent connections with very few threads.
Blocking vs Non-Blocking
In a blocking model, a thread waits idle while a backend responds. In a non-blocking model, the thread is freed and notified later when data is ready.
- Blocking: 1 thread tied up per in-flight request
- Non-blocking: a handful of threads serve many requests
Mono and Flux
Reactor's core types describe asynchronous results:
Mono<T>emits 0 or 1 valueFlux<T>emits 0 to many values
The gateway returns a Mono<Void> when a request finishes processing.
Mono<String> name = Mono.just("gateway");
Flux<Integer> nums = Flux.just(1, 2, 3);Nothing Happens Until Subscribe
Reactive streams are lazy. A Mono or Flux does nothing until something subscribes. In the gateway, the framework subscribes for you when a request arrives.
Mono<String> greeting = Mono.fromSupplier(() -> "hello");
// runs only when subscribed:
greeting.subscribe(System.out::println);The Reactive Web Stack
The starter spring-cloud-starter-gateway pulls in WebFlux automatically. You must not add spring-boot-starter-web (the servlet/MVC stack) or startup will fail with a conflict.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>The ServerWebExchange
Every request is wrapped in a ServerWebExchange, which holds the request and response. Filters read and mutate this exchange as the request flows through.
// inside a filter
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();The Filter Chain
A request passes through an ordered chain. Each filter can act, then call chain.filter(exchange) to continue, and run more logic after the downstream response returns.
return chain.filter(exchange)
.then(Mono.fromRunnable(() ->
System.out.println("response sent")));Why Reactive Fits a Gateway
A gateway spends most of its time waiting on the network for upstream services. Non-blocking I/O is ideal here: threads are not wasted waiting, so the gateway stays responsive under heavy load.
Avoid Blocking Calls
Calling a blocking JDBC driver or Thread.sleep inside a filter stalls the event loop and hurts every request. If you must block, offload to a bounded scheduler.
Mono.fromCallable(() -> blockingLookup())
.subscribeOn(Schedulers.boundedElastic());Operators Transform Streams
Operators like map, flatMap, and filter reshape the data flowing through a stream without blocking.
Flux.just(1, 2, 3, 4)
.filter(n -> n % 2 == 0)
.map(n -> n * 10)
.subscribe(System.out::println); // 20, 40Mental Model
Think of the gateway as a pipeline of asynchronous steps. A request enters, flows through predicates and filters, is forwarded reactively, and the response streams back through the same chain in reverse.
Quick Check
What underlying web stack does Spring Cloud Gateway run on?
Recap
You now understand the reactive foundation of the gateway:
- Non-blocking I/O on Netty handles high concurrency
MonoandFluxmodel async results and are lazy- Each request is a
ServerWebExchangeflowing through a filter chain - Never block the event loop
This mindset underpins routes, predicates, and filters you build next.
Lerne API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 12
- Lektionen
- 48
Häufig gestellte Fragen
Ist die Lektion „Die reaktive Grundlage verstehen“ kostenlos?
Ja — der vollständige Text von „Die reaktive Grundlage verstehen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Die reaktive Grundlage verstehen“?
Entdecken Sie, warum Spring Cloud Gateway auf einem nicht blockierenden reaktiven Stack basiert und was das für den Weg von Anfragen durch das Gateway bedeutet. Du übst API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) zu starten?
Keine Vorkenntnisse erforderlich. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Die reaktive Grundlage verstehen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Lektion Code schreiben und ausführen?
Ja. Jede API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Gateway vs. traditionelle Microservices
- Ein einfaches Gateway-Projekt einrichten
- Routen und Prädikate definieren
- Die reaktive Grundlage verstehen