====== Spring WebFlux ====== * Spring 5 의 Non Blocking IO/Reactive Web Framework * [[reactive_programming:reactor|Project Reactor]] 기반 * [[https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html|Web on Reactive Stack]] * [[springframework:webclient|WebClient]] * [[springframework:springboot:test|SpringBoot Test]] ===== Servlet과의 성능 차이 ===== * [[https://blog.devgenius.io/is-spring-webflux-a-myth-4526c2f92413|Is Spring WebFlux a Myth?. Does it really outperform Spring… | by Gavin Fong | Aug, 2021 | Dev Genius]] * 응답속도가 매우 좋은 환경에서는 servlet보다 느릴 경우도 존재할 수 있지만, 고 부하에 응답속도 편차가 큰 일반적인 환경에서는 WebFlux/non-blocking의 성능이 압도적으로 좋고 실패율도 낮다. ===== SpringBoot WebFlux Customize ===== * [[https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/config/WebFluxConfigurer.html|WebFluxConfigurer]] 를 구현한다. * [[springframework:springboot:json|SpringBoot and JSON]] 에서 [[java:jackson|Java Jackson JSON Library]] 설정 확인 ===== Swagger 설정 ===== * [[springframework:springfox|SpringFox]] 3.x 부터 webflux 지원. * [[https://itstory.tk/entry/springbootstarterwebflux-swagger-3-%EC%84%A4%EC%A0%95|spring-boot-starter-webflux swagger 3 설정]] ===== APM ===== * [[https://blog.newrelic.com/product-news/newrelic-announces-support-spring5-webflux/|NewRelic 이 spring webflux 지원]] * [[https://github.com/scouter-project/scouter/releases/tag/v2.5.0|Scouter 2.5.0 부터 Spring Reactor 지원]] ===== Routes ===== * 라우터를 여러개 생성해도 자동으로 모두 모아서 설정해준다. * 단, 각 **라우터 Bean의 이름은 모두 달라야 한다.** ===== 참고 ===== * [[https://www.youtube.com/watch?v=2E_1yb8iLKk|스프링캠프 2017 [Day1 A3] : Spring Web Flux - YouTube]] * [[https://www.youtube.com/watch?v=UIrwrW5A2co|스프링캠프 2017 [Day2 A1] : Reactive Spring ( Spring 5 & Reactor ) - YouTube]] * [[https://www.javaworld.com/article/3288219/spring-framework/mastering-spring-framework-5-part-2-spring-webflux.amp.html|Mastering Spring framework 5, Part 2: Spring WebFlux | JavaWorld]] * [[http://www.java-allandsundry.com/2018/12/reactive-spring-webflux-with-aws.html|all and sundry: Reactive Spring Webflux with AWS DynamoDB]] * [[http://wiki.sys4u.co.kr/display/SOWIKI/Reactive+Programming+with+Spring+Boot|Reactive Programming with Spring Boot]] * [[https://www.baeldung.com/spring-webflux|Guide to Spring WebFlux]] * [[https://thepracticaldeveloper.com/2017/11/04/full-reactive-stack-with-spring-webflux-and-angularjs/|Full Reactive Stack with Spring Boot WebFlux]] * [[https://inyl.github.io/programming/2018/03/10/springboot2_api.html|Spring boot2로 Reactive Webflux API 만들기 1]] ''@WebFluxTest''포함. * [[https://developer.okta.com/blog/2018/09/24/reactive-apis-with-spring-webflux|Build Reactive APIs with Spring WebFlux | Okta Developer]] * [[https://www.baeldung.com/spring-webflux-kotlin|Spring Webflux with Kotlin | Baeldung]] * [[http://hyper-cube.io/2017/11/27/spring5-with-kotlin/|Spring 5 with Kotlin · hyper-cube.io]] * [[http://www.mkyong.com/spring-boot/spring-boot-webflux-server-sent-events-example/|Spring Boot WebFlux + Server-sent events example – Mkyong.com]] * [[https://www.baeldung.com/spring-webflux-errors|Handling Errors in Spring WebFlux | Baeldung]] * [[https://blog.softwaremill.com/spring-webflux-and-domain-exceptions-10ae2096b159|Spring Webflux and domain exceptions – SoftwareMill Tech Blog]] * [[https://dzone.com/articles/exception-handling-in-spring-boot-webflux-reactive|Exception Handling in Spring Boot WebFlux Reactive REST Web Services - DZone Integration]] * [[https://www.baeldung.com/spring-webflux-concurrency?utm_medium=feed|Concurrency in Spring WebFlux | Baeldung]] * [[https://www.youtube.com/watch?v=I0zMm6wIbRI|내가 만든 WebFlux가 느렸던 이유]] * blocking 호출을 map 에서 수행해서 -> flatMap * ''map'' 남발. ''map''을 사용할 때마다 새로운 객체 생성 -> Memory 증가 * ''log()'' 남발. log appender 를 non-blocking 으로 변경할 것. ''AsyncAppender'' 만으로는 안된다. * Test code에 BlockHound 사용해서 blocking call 탐지 * blocking 이 꼭 필요하면 ''subscribeOn()'', ''publishOn()'' 사용 * [[https://www.baeldung.com/spring-webflux-static-content|Static Content in Spring WebFlux | Baeldung]]