liveBook · Manning

RxJava

As explained in Spring in Action, Sixth Edition

RxJava is a Java implementation of the ReactiveX programming model for composing asynchronous and event-based sequences.

RxJava applies the ReactiveX programming model to Java and integrates with Spring WebFlux through asynchronous, event-oriented return types. WebFlux controllers can return Observable, Single, Completable, or Flowable instead of ordinary values or Reactor types. section 12.1.2

Common controller mappings include:

  • Return Observable<Taco> for a sequence, such as recent tacos supplied by a service. section 12.1.2
  • Return Single<Taco> for a single lookup, paralleling Reactor's Mono. section 12.1.2
  • Use Completable for no-value completion or Flowable as an alternative to Observable. section 12.1.2

Reactive taco lookup

A controller can delegate an identifier lookup to a service and return the result directly: `public Single<Taco> tacoById(@PathVariable("id") Long id) { return tacoService.lookupTaco(id); }`. section 12.1.2

@GetMapping(params = "recent")
public Observable<Taco> recentTacos() {
  return tacoService.getRecentTacos();
}

Browse a complete controller method returning an RxJava Observable for recent results. section 12.1.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Demonstrates controller return and input types, but stops short of explaining RxJava internals.
Examples
Uses recent-taco Observable endpoints, Single-based taco lookup, and reactive POST handling.
What it assumes
Assumes familiarity with Java controllers, Spring WebFlux, services, and repositories.
What you can do after
Apply RxJava types in Spring WebFlux controller methods for reactive responses and request bodies.
How it connects
Connects RxJava with Spring WebFlux, reactive repositories, Reactor, Observable, Single, Completable, and Flowable.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.