The session provides details about reactive programming with reactive streams. The purpose of Reactive Streams is to provide a standard for asynchronous stream processing with non-blocking backpressure.”
This concept is explained using Project reactor.
4. Reactive Programming
● Programming paradigm oriented around - data flows and propagation of change.
● Asynchronous and Non Blocking.
● Data flow as an Event/Message Driven stream
6. Reactive Streams
Reactive Streams is an initiative to provide a standard for asynchronous stream
processing with non-blocking back pressure.
Back Pressure
Deferred Push/Pull
Model
Functional Style Code
Java 8 Streams API
Lambdas
Event Driven Streams
● Event or Message for
every result item from
Data Source
● Event or Message for
Completion or error
● Asynchronous and
non-blocking
E
F
B
D
8. Reactive Stream Specification
Specification or Rules for a Reactive Stream
(Created by Pivotal, Netflix, LightBend, Twitter etc...)
Publisher Subscriber Subscription Processor
9. Publisher
public interface Publisher<T> {
public void subscribe(Subscriber<? super T> s);
}
● Represents the Data source
○ Database
○ External Service, etc…..
10. Subscriber
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
● Represents the consumer of the stream data
12. Processor
public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}
● A Processor represents a processing stage—which is both a Subscriber and a Publisher.
19. Project Reactor
● Reactor is a fully non-blocking reactive programming foundation for the JVM, with efficient demand management
(in the form of managing "backpressure").
● Integrates directly with the Java 8 functional APIs, notably CompletableFuture, Stream, and Duration.
● Reactive Types - Offers asynchronous sequence (MONO/FLUX) for reactive streams
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
20. Mono
● Publisher<T> that emits at most one item
● Optionally terminates with an onComplete signal or an onError signal.
21. Flux
● Publisher<T> that emits 0 to n items
● Optionally terminates with an onComplete signal or an onError signal.