Reactive Streams

Reactive Streams started as an initiative in late 2013 between engineers at Netflix, Pivotal and Lightbend.

Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. This encompasses efforts aimed at runtime environments (JVM and JavaScript) as well as network protocols.

You can read the origin specification on official website of Reactive Streams.

Also, you can read the Chinese translation from here.

Asynchronous stream processing with non-blocking back pressure.

The Reactive Streams is composed of following:

  1. Asynchronous;
  2. Stream;
  3. Non-blocking;
  4. Back pressure.

The Java interfaces, you can find details on GitHub.

public interface Publisher<T> {
    public void subscribe(Subscriber<? super T> s);
}

public interface Subscriber<T> {
    public void onSubscribe(Subscription s);
    public void onNext(T t);
    public void onError(Throwable t);
    public void onComplete();
}

public interface Subscription {
    public void request(long n);
    public void cancel();
}

public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}

Reactive Extensions

An API for asynchronous programming with observable streams

ReactiveX is a combination of the best ideas from the Observer pattern, the Iterator pattern, and functional programming

Reactive Extensions

Project Reactor

Reactor is a fourth-generation Reactive library for building non-blocking applications on the JVM based on the Reactive Streams Specification

  • Composability and readability
  • Data as a flow manipulated with a rich vocabulary of operators
  • Nothing happens until you subscribe
  • Backpressure or the ability for the consumer to signal the producer that the rate of emission is too high
  • High level but high value abstraction that is concurrency-agnostic

From Imperative to Reactive Programming

Features:

  1. Fully non-blocking.
  2. Integrates Java API.
    1. Completable Future
    2. Stream
    3. Duration
  3. Flux and Mono.
    1. Flux: A Reactive Streams Publisher with rx operators that emits 0 to N elements, and then completes.
    2. Mono: A Reactive Streams Publisher with basic rx operators that completes successfully by emitting an element, or with an error.
  4. Implements the Reactive Streams specification.

You can find details on GitHub.

By the way, you can follow the Lite Rx API Hands-on to learn the basic APIs.

And here How to Choose Operators.

Reactor Netty

Reactor Netty offers non-blocking and backpressure-ready TCP/HTTP/UDP clients & servers based on Netty framework.

Reactor Netty

Spring Framework WebFlux

The reactive-stack web framework, Spring WebFlux, was added later in version 5.0. It is fully non-blocking, supports Reactive Streams back pressure, and runs on such servers as Netty, Undertow, and Servlet 3.1+ containers

Spring WebFlux

debug

  1. .checkpoint
  2. Hooks.onOperatorDebug()
  3. reactor-tools ReactorDebugAgent (works in production) java agent

RSocket

A binary protocol based on Reactive Streams back pressure

Features

  1. bi-directional
  2. multiplexed
  3. message-based
  4. binary protocol

Interaction Models

  1. request-response (1 to 1)
  2. fire and forget (1 to 0 udp)
  3. request stream (1 to many pub / sub)
  4. request channel (many to many)

Protocol

  • WebSocket
  • TCP
  • UDP

Summary

Reactive Streams is a specification.

Project Reactor is JVM implementation base on the specification.

Spring WebFlux is Spring framework integration with Project Reactor.

RSocket is binary protocol base on the specification.

References