40. #JCConfTaiwan 2017
Reactor Core Features
• Flux, an asynchronous sequence of 0-n items
• Mono, an asynchronous 0-1 result
• Simple ways to create a Flux/Mono and to
subscribe to it
• Programmatically creating a sequence
• Schedulers
• Handling Errors
• Processor
54. #JCConfTaiwan 2017
Scheduler Threading
• Schedulers.immediate()
current thread
• Schedulers.single()
single, reusable thread
• Schedulers.elastic()
elastic thread pool
• Schedulers.parallel()
fixed pool of workers(CPU cores)
•Schedulers.fromExecutorService(ExecutorService)
55. #JCConfTaiwan 2017
Scheduler Threading (ex: Flux)
Ref: https://stackoverflow.com/a/41941592
Flux.just("a", "b", "c")
.doOnNext(v -> System.out.println("before publishOn: " + Thread.currentThread().getName()))
.publishOn(Schedulers.elastic())
.doOnNext(v -> System.out.println("after publishOn: " + Thread.currentThread().getName()))
.subscribeOn(Schedulers.parallel())
.subscribe(v -> System.out.println("received " + v + " on " + Thread.currentThread().getName()));
before publishOn: parallel-1
before publishOn: parallel-1
before publishOn: parallel-1
after publishOn: elastic-2
received a on elastic-2
after publishOn: elastic-2
received b on elastic-2
after publishOn: elastic-2
received c on elastic-2
Output:
59. #JCConfTaiwan 2017
Ref. Reactive Programming with Reactor
• Project Reactor
https://projectreactor.io/
• Reactive Programming versus Reactive Systems
https://www.lightbend.com/reactive-programming-versus-reactive-systems
• Reactive Programming with Reactor 3
https://tech.io/playgrounds/929/reactive-programming-with-reactor-3/Intro
• What Are Reactive Streams in Java?
https://dzone.com/articles/what-are-reactive-streams-in-java
• 5 Things to Know About Reactive Programming
https://dzone.com/articles/5-things-to-know-about-reactive-programming
• Java 9 Flow API – Reactive Streams
http://javasampleapproach.com/java/java-9/java-9-flow-api-reactive-streams