Spring/Spring

[Spring / WebFlux] WebFlux , Spring 5

SIXXXX_ 2022. 7. 19. 16:25
728x90

Spring 5 에서 새롭게 추가된 모듈로서

WebFlux는 클라이언트, 서버에서 reactive 스타일의 어플리케이션 개발을 도와주는 모듈이며,

reactive-stack web framework 이며 non-blockingreactive stream 을 지원한다.

 

*reactive-stack : 

https://spring.io/reactive 좀더 영어로 쉽게 이해하기

message-driven 메세지 기반 , elastic 융통성, resilient 복구가 쉬운, responsive 응답성 인

enterprise-grade reactive system 으로 build 하기 위해 사용하는것이랜다.

 

이벤트 루프, 비차단 실행 모델을 기반으로 하여 더 적은 하드웨어 리소스로 높은 동시성을 처리할 수 있는

'Reactive Stack' : Spring WebFlux와 Spring Data 반응형 저장소 (Reactive Repositories)를 활용.

Tomcat, Jetty 외에도 Servlet 3.1+ Container 와 Netty, Undertow 같은 논블로킹 서버 위에서 구동된다.

 

 

출처 : https://www.infoq.com/articles/Servlet-and-Reactive-Stacks-Spring-Framework-5/

 

 

 

출처 : https://www.infoq.com/articles/Servlet-and-Reactive-Stacks-Spring-Framework-5/

 

 

WebFlux의 장점 : 고성능, Spring 과 완벽한 통합, netty 지원, 비동기 non-blocking 메세지 처리

WebFlux의 단점 : 오류처리가 다소 복잡하다, Back Pressure 기능 없음

 

 

Spring MVC 와 Spring WebFlux 사이

@Controller : Reactive Clients : Tomcat, Jetty, Undertow

Spring WebFlux : Functional endpoints : Event loop - concurrency model, Netty

Spring MVC : Imperative logic, simple to write and debug JDBC, JPA, blocking deps

 

 

 

1 request : 1 thread

sync + blocking

 

Spring WebFlux는

many request : 1 thread

async + nonblock

 

 

db가 blocking이라면?  WebFlux를 쓸 이유가 없다 >> reactive 를 지원하는 DB를 사용해야 되는데

Mongo DB, Redis등을 지원한다*RDBMS는 R2DBC(Microsoft SQL Server, Spring R2DBC)를 이용하면 mysql 등과 비동기 방식으로 연결가능?

 

 

 

Spring Boot (Reactive) + R2DBC + MySQL  Driver 으로 한 예시를  출처에서 볼 수 있다

나는 spring.io에서 긁어왔고 나는 h2, mysql 사용해서 해보려고 한다.

H2와 Spring Data R2DBC 비교

 

 

 

더보기

히이.. 어렵소.. 안하다하니까..tjfwjdqnxj akrglsmsrj tlfghksi...?

 

 

 

 

 

출처

 

https://devuna.tistory.com/108

https://gompangs.tistory.com/entry/Spring-R2DBC-MySQL

 

 

 

 

 

 

 

 

 

 

 

 

 

 

https://starblood.tistory.com/entry/Reactive-Manifesto

 

Reactive Manifesto

Reactive Programming 이 붐이다. 우리나라는 어떻게 진행되고 있는 지 몰라도 해외에서는 이 패러다임이 대세인 것이다. 특히 미국에서. 오늘은 그래서 이 프로그래밍 패러다임이 도대체 어떤 것을

starblood.tistory.com