Callbacks • Callbacks are hard to compose together - known as "Callback Hell" • Futures • Easy to block – get • Complex orchestrating beyond one level of composition • No support for multiple values and advanced error handling
to handle requests in a reasonable time. • Resilient • a reactive system must stay responsive in the face of failures. • it must be designed for failures and deal with them appropriately. • Elastic • a reactive system must stay responsive under various loads. • it must scale up/down and be able to handle the load with minimal resources. • Message Driven • components from a reactive system interacts using asynchronous message passing.
a concurrency model • Scheduler – the execution model and where the execution happens • immediate – current thread • single – reuses the same thread for all callers • newSingle – a per-call dedicated thread • elastic – elastic thread pool • creates new worker pools as needed • reuse idle ones • worker pools that stay idle for long time are disposed • parallel – fixed thread pool • creates as many workers as you have CPU cores Schedulers and Threading
subscribeOn and publishOn operators • subscribeOn • applies to the subscription process, when that backward chain is constructed. • it always affects the context of the source emission. • publishOn • applies in the same way as any other operator, in the middle of the subscriber chain. • it affects where the subsequent operators will execute Schedulers and Threading
event. • One element received Flux<User> findAll(); • Method returns immediately • Elements are received as soon as they are available, ending with a success "onComplete" event. Reactive Repository