Skip to content

Spring Framework Blog

Menu
  • Home
  • Spring
  • Spring Boot
  • About
Menu

Reactive programming

Posted on January 30, 2024May 27, 2024 by Armando Marques

Table of Contents

Toggle
  • Implementations
    • Project Reactor
    • RxJava
    • Java9 Reactive Flow
  • Backpressure strategies

Implementations

Reactive programming is a programming paradigm associated with non-blocking, asynchronous and event driven processing of data streams. It facilitates automatic propagation of data flow.

Implementations: Project Reactor, RxJava, Java9 Reactive Flow.

https://medium.com/globant/reactive-programming-project-reactor-rx-java-java-9-reactive-flow-881f5070f7df

There are four interfaces:

Publisher
---
subscribe(Subscriver<> subscriber)

Subscriber
---
onSubscrive(Subscription subscription)
onNext(T item)
onError(Throwable t)
onComplete()

Subscription
---
request(Long n)
cancel()

Processor
---
extends Subscriver<T>, Publisher<T>

Project Reactor

Spring WebFlux, provides two data types:

  • Flux – Publisher 0-N elements
  • Mono Publisher 0-1 elements

RxJava

Java extension of ReactiveX

Observables – any object can get data from data source and which state maybe of interest in a way that others can register interest (Publisher).

Observer – any object that wishes to be notified when a state of another object changes.

RxJava Observables

  • Observable: 0-N items, not backpressure enabled.
  • Flowable: 0-N items, with backpressure.
  • Completable: doesn’t emit any item.
  • Single: emits only one item or error.
  • Maybe: emits zero or one item.

Java9 Reactive Flow

Reactive Streams (java.util.concurrent.Flow)

Publisher, Subscriber, Subscription and Processor interfaces.

Backpressure strategies

  • Control the producer
  • Buffering (accumulate incoming data)
  • Drop (sample a percentage of incoming data)

Some stategies:

Pull – consumer controls producer (1:1 request style, Flowables in RxJava).

Push – producer in control, pushed data to consumer when it’s available.

  • Spring
  • Documentation
  • References
  • Toc
  • Books
  • Certification
  • AOP
  • Config
  • Java
  • Java core
  • JDBC
  • JPA
  • Rest
  • Security
  • Spring
  • Spring Boot
  • Spring Core
  • Spring Data
  • Spring MVC
  • Spring Rest
  • Spring Security
  • Tests
  • Transactions
  • Uncategorized

Recent Posts

  • Spring Annotations
  • Java Tests
  • Java operators
  • Java versions
  • Java Oracle Licenses
  • Configuration properties
  • MockMvc
  • Spring Security III
  • MVC Controller Method Params
  • JPA Methods
  • Transaction propagation and isolation
  • Spring JDBC
  • Spring Boot Auto-Configuration
  • Spring Resource interface
  • JSR 330 Standard Annotations
  • Spring Aware Interfaces
  • Spring Transactions
  • Spring Boot Core
  • MVC Rest
  • Spring Boot JPA
©2025 Spring Framework Blog | Built using WordPress and Responsive Blogily theme by Superb