daehwan2yo / msa-playground

MSA 를 멀티모듈기반으로 연습합니다.
2 stars 0 forks source link

Spring, Web on Reactive Stack #10

Open daehwan2yo opened 2 years ago

daehwan2yo commented 2 years ago

Web on Reactive Stack

reference

https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html

daehwan2yo commented 2 years ago

Spring MVC or Spring WebFlux

refernce

https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-framework-choice

daehwan2yo commented 2 years ago

DispatcherHandler

reference

https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-dispatcher-handler

WebFlux 도 WebMVC 와 마찬가지로 front controller pattern 으로 설계되었다. WebMVC 에서 DispatcherServlet 이 Central Servlet 으로서 front controller 역할을 수행했듯이, DispatcherHandler 역시 Central WebHandler 로써 front handler 역할을 수행한다. (WebHandler 의 핵심 구현체)

DispatcherHandler implements WebHandler, PreFlightRequestHandler, ApplicationContextAware, Aware{ ... }

Spring Configuration in a WebFlux application typically contains

https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-framework-config

daehwan2yo commented 2 years ago

Mono

Mono is one of Publisher in Project Reactor, which emits 0 or 1 item.

Keywords

Mono, Asynchronous, non-blocking, functional, pipe-line

Mono.fromSupplier( () -> {
  System.out.println("Generating name..");
  Util.sleepSeconds(3);
  return Util.faker().name().fullName();
});

Creating Mono, Data already present

실제는 거의 사용하지 않는다. 테스트 및 학습용 Mono.just(data)

Creating Mono, Data to be calculated

람다를 활용하며, pipe line 을 구성하며 데이터가 흘러간다. Mono.fromSupplier(() -> getData()) 혹은 Mono.fromCallable(() -> getData())

Creating Mono, Data is coming from async CompletableFuture

비동기적으로 쓰레드를 분할하여 처리하는 경우 (병렬 프로그래밍) Mono.fromFuture(future)

Creating Mono, Emit Empty once a given runnable is completed

Runnable 이며 void -> void 로, 어떤 행위만 수행한다. (비즈니스 로직이 비동기적으로 완성되면 알람을 울리거나, email 을 보내는 등 행위만) Mono.fromRunnable(runnable)