Reactive programming is a programming paradigm, but I wouldn’t call it new. It’s actually been around for a while. Just like object-oriented programming, functional programming, or procedural programming, reactive programming is another programming paradigm.
Paradigm is defined by Reactive Manifesto
Reactive Streams, on the other hand, is a specification.
For Java programmers, Reactive Streams is an API. It is the product of a collaboration between engineers from Kaazing, Netflix, Pivotal, Red Hat, Twitter, Typesafe, and many others. Reactive Streams is much like JPA or JDBC. Both are API specifications.
The Reactive Streams API consists of just 4 high interfaces.
- Publisher :
A publisher is a provider of a potentially unbounded number of sequenced elements, publishing them according to the demand received from its Subscribers.
- Subscriber :
Will receive call to Subscriber.onSubscribe(Subscription) once after passing an instance of Subscriber to Publisher. subscribe(Subscriber).
- Subscription :
A Subscription represents a one-to-one lifecycle of a Subscriber subscribing to a Publisher.
- Processor :
A Processor represents a processing stage—which is both a Subscriber and a Publisher and obeys the contracts of both.
These concepts take different manifestations at different levels and areas. For eg. A java dev could think about how to program his at the application level, a database engineer could think how a database could react to reactive API calls (For example, Mongo DB has implemented a Reactive Streams driver), a network programmer could think how reactive calls could be made effective at the network level.
Some of the JVM-based frameworks that follow the reactive streams spec are
- Akka Streams framework
- Ratpack
- Vert.x
- ReactiveX (RxJava 2.x and Reactor)
- Java 1.9 Flow classes (You’ll notice that the Reactive Streams interfaces move under the Flow class in Java 9)
ReactiveX is a combination of the best ideas from the Observer pattern, the Iterator pattern, and functional programming. It extends the observer pattern to support sequences of data and/or events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety, concurrent data structures, and non-blocking I/O.
RxJava 2.0 and Reactor are based on ReactiveX project. And Spring WebFlux uses Reactor internally.