Giter VIP home page Giter VIP logo

Comments (3)

daehwan2yo avatar daehwan2yo commented on June 10, 2024

Spring MVC or Spring WebFlux

refernce

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

  • MVC application 이 정상적으로 동작되어지고 있다면, 바꿀 필요가 없다. 오히려 명령형 프로그래밍으로 작성된 로직이 더 가시성이 좋고, 작성하기 쉽고, 디버깅에 유리하다.
  • 경량화를 원한다면 java8 혹은 kotlin 을 활용한 Spring WebFlux Functional Web endpoint 를 활용하면 좋다.
    (이는 작은 규모의 application 혹은 micro service의 component 로써 좋다)
  • MSA 구조에서는 Spring MVC 혹은 WebFlux Controller 혹은 WebFlux Functional endpoint 를 혼합해서 사용해도 무방하다.
  • 라이브러리 호환에도 신경써야한다.
    만약 blocking api (JDBC, JPA) 혹은 blocking api 를 활용중이라면, MVC 가 유리하다.
    Reactor 나 RxJava 가 blocking call 에 대응할 수는 있으나, 그렇게되면 non-blocking web stack 을 완전히 활용하지는 못할것이다.

from msa-playground.

daehwan2yo avatar daehwan2yo commented on June 10, 2024

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 을 통해 Delegate Component 를 discover
  • ApplicationContextAware를 구현하므로써, 실행되어지는 Context에 access

Spring Configuration in a WebFlux application typically contains

  • DispatcherHandler with Bean name WebHandler
  • WebFilter, WebExceptionHandler Beans
  • DispatcherHandler Special Beans

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

from msa-playground.

daehwan2yo avatar daehwan2yo commented on June 10, 2024

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())

  • 이때 비동기적으로 쓰레드를 병렬을 활용하여 사용할 경우, subscribeOn(Schedulers) 를 통해 ExecutorService 를 등록해준다.

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)

from msa-playground.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.