사용자 도구

사이트 도구


reactive_programming:reactor

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
reactive_programming:reactor [2018/12/28 15:35]
kwon37xi
reactive_programming:reactor [2020/11/17 15:18] (현재)
kwon37xi
줄 2: 줄 2:
   * http://projectreactor.io/   * http://projectreactor.io/
   * [[reactive_programming:reactive_streams|Reactive Streams]] 구현.    * [[reactive_programming:reactive_streams|Reactive Streams]] 구현. 
 +  * [[https://projectreactor.io/docs/core/release/reference/#which-operator|Reactor 3 Reference Guide - 어떤 연산자를 사용할 것인가?]]
 +
 +===== 동기 호출을 비동기로 전환하기(JDBC 등) =====
 +  * ''CompletableFuture'', ''@Async'', 그리고 Reactor가 제공해주는 기능등을 통해 동기 호출을 쓰레드 기반 비동기로 전환할 수 있다.
 +  * [[https://stackoverflow.com/questions/42299455/spring-webflux-and-reading-from-database|reactive programming - Spring webflux and reading from database - Stack Overflow]]
 +  * [[https://projectreactor.io/docs/core/release/reference/#faq.wrap-blocking|Reactor 3 Reference Guide Blocking 호출을 비동기로 전환하기]] 
 +  * [[https://dzone.com/articles/spring-5-webflux-and-jdbc-to-block-or-not-to-block|Spring 5 WebFlux and JDBC: To Block or Not to Block - DZone Java]]
 +  * [[https://musigma.blog/2016/11/21/reactor.html|Reactive systems using Reactor]]
 +  * [[java:jpa:springdatajpa|Spring Data JPA]] ''@Aync'' 참조. ''CompletableFuture'' -> ''Mono/Flux'' 전환 가능
 +
 +<code java>
 +Mono blockingWrapper = Mono.fromCallable(() -> { 
 +    return /* make a remote synchronous call */ 
 +});
 +blockingWrapper = blockingWrapper.subscribeOn(Schedulers.elastic()); 
 +</code>
 +
 +<code java>
 +@GetMapping(value = "/v1/measurements")
 +public Flux<Measurement> getMeasurements() {
 +    return Flux.defer(() -> Flux.fromIterable(repository.findByFromDateGreaterThanEqual(new Date(1486980000L))))
 +           .subscribeOn(Schedulers.elastic());
 +}
 +</code>
 +
 +<code java>
 +@Configuration
 +public class SchedulerConfiguration {
 +    private final Integer connectionPoolSize;
 +    public SchedulerConfiguration(@Value("${spring.datasource.maximum-pool-size}") Integer connectionPoolSize) {
 +        this.connectionPoolSize = connectionPoolSize;
 +    }
 +    @Bean
 +    public Scheduler jdbcScheduler() {
 +        return Schedulers.fromExecutor(Executors.newFixedThreadPool(connectionPoolSize));
 +    }
 +}
 +
 +@Service
 +public class AddressService {
 +    private final AddressRepository repository;
 +    private final Scheduler scheduler;
 +    public AddressRouter(AddressRepository repository, @Qualifier("jdbcScheduler") Scheduler scheduler) {
 +        this.repository = repository;
 +        this.scheduler = scheduler;
 +    }
 +    public Mono<Iterable<Address>> findAll() {
 +        return async(() -> repository.findAll());
 +    }
 +    private <T> Mono<T> async(Callable<T> callable) {
 +        return Mono.fromCallable(callable).publishOn(scheduler);
 +    }
 +}
 +</code>
 +
 +===== Tuning =====
 +  * [[reactive_programming:block_hound|Block Hound]]
  
 ===== 참조 ===== ===== 참조 =====
줄 12: 줄 69:
   * [[https://spring.io/blog/2016/03/11/reactor-core-3-0-becomes-a-unified-reactive-foundation-on-java-8|Reactor Core 3.0 becomes a unified Reactive Foundation on Java 8]]   * [[https://spring.io/blog/2016/03/11/reactor-core-3-0-becomes-a-unified-reactive-foundation-on-java-8|Reactor Core 3.0 becomes a unified Reactive Foundation on Java 8]]
   * [[http://tech.kakao.com/2018/05/29/reactor-programming/|사용하면서 알게 된 Reactor, 예제 코드로 살펴보기]]   * [[http://tech.kakao.com/2018/05/29/reactor-programming/|사용하면서 알게 된 Reactor, 예제 코드로 살펴보기]]
 +  * [[https://piotrminkowski.wordpress.com/2018/10/22/reactive-programming-with-project-reactor/|Reactive programming with Project Reactor – Piotr's TechBlog]]
 +  * [[https://spring.io/blog/2019/02/06/spring-tips-testing-reactive-code|Spring Tips: Testing Reactive Code]]
 +  * [[https://dzone.com/articles/spring-tips-the-reactor-context-video|Spring Tips: The Reactor Context [Video] - DZone Java]]
 +  * [[https://spring.io/blog/2019/05/29/spring-tips-debugging-reactor-applications|Spring Tips: Debugging Reactor Applications]]
 +  * [[https://www.youtube.com/watch?v=xCu73WVg8Ps&t=2467s|(26) Avoiding Reactor Meltdown - YouTube]]
 +  * [[https://github.com/nurkiewicz/reactor-workshop|nurkiewicz/reactor-workshop: Spring Reactor hands-on training (3 days)]]
 +  * [[https://www.logicbig.com/tutorials/misc/reactive-programming/reactor.html|Reactive Programming with Reactor]]
 +  * [[https://dlsrb6342.github.io/2019/11/23/Reactor-Tools-%EC%82%AC%EC%9A%A9%ED%95%B4%EB%B3%B4%EA%B8%B0/|Reactor-Tools 사용해보기]]
reactive_programming/reactor.1545978921.txt.gz · 마지막으로 수정됨: 2018/12/28 15:35 저자 kwon37xi