For composing asynchronous and event-based programs by using observable sequences • Easy way to implement complicated non-blocking system • Easy to combine multiple data source responses • Resiliency / Fault tolerance / Deal heavy load • Why Reactive
Data published then 0..1 (Error or Completed) Example : Using Message Queue 1. Polling message queue for new message (traditional Kafka client) 2. Listener or callback for new message (spring-kafka use listener) 3. Reactive stream (kakfa streams) is reactive streams
Flexible • Observables are less opinionated • Various implementation (thread-pool, event loops, non- blocking I/O) • Callback is hard to implement and maintain • Not only for UI, Useful for Distributed System
(Video on demand) (Finite stream) • At time to subscribe, you can receive first data • Other subscribe, receive first data also • Hot Observable • Like TV or Radio (Infinite Stream) • At time to subscribe, you can receive published data at that time
AsyncSubject - take last elements • BehaviorSubject - like hot observable + latest element • PublishSubject - like hot observable • ReplaySubject - cold observable
emit data - subscribeOn(scheduler) • Scheduling subscribe data - observeOn(scheduler) • Type of schedulers • computation, io, newThread, single, trampoline, from … • TestScheduler for simulate Observable timely emit