BAEL-4107: Spring MVC Async vs Spring WebFlux
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.spring.asyncvsflux;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class AsyncVsWebFluxApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AsyncVsWebFluxApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.spring.asyncvsflux;
|
||||
|
||||
import java.time.Duration;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
public class WebFluxController {
|
||||
|
||||
@GetMapping("/flux_result")
|
||||
public Mono<String> getResult(ServerHttpRequest request) {
|
||||
return Mono.defer(() -> Mono.just("Result is ready!"))
|
||||
.delaySubscription(Duration.ofMillis(500));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.spring.asyncvsflux;
|
||||
|
||||
import java.time.Duration;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
public class WebFluxFilter implements org.springframework.web.server.WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
|
||||
return Mono
|
||||
.delay(Duration.ofMillis(200))
|
||||
.then(
|
||||
webFilterChain.filter(serverWebExchange)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user