liveBook · Manning

Mono

As explained in Spring Start Here, Second Edition

Mono is a Reactor publisher type that represents an asynchronous computation producing zero or one result.

Mono is a Reactor publisher for an asynchronous computation that produces zero or one result. It represents work that another task can subscribe to, rather than a value returned directly. section 11.4

In a WebClient call, a Mono can supply the request body and represent the response. Linking these producers and consumers defines task dependencies without chaining work on a single thread. section 11.4

A payment request

A proxy sends Mono.just(payment) as the POST body and returns bodyToMono(Payment.class). WebFlux subscribes to the returned task; WebClient subscribes to the body task. section 11.4

Figure 11.10 The tasks chain in a reactive app. When building a reactive web app, we define the tasks and the dependencies between them. The WebFlux functionality, initiating the HTTP request, subscribes to the task we create through the producer the controller’s action returns. In our case, this producer is the one we get by sending the HTTP request with WebClient. For WebClient to make the request, it subscribes to another task that provides the request body.

Trace how the response task and request-body task depend on one another through subscriptions. section 11.4

How Spring Start Here, Second Edition covers it

How deep it goes
Defines Mono through producer-consumer subscriptions and task dependencies in a payment proxy example.
Examples
Uses a payment object as the request body and a Payment response from a WebClient call.
What you can do after
Apply Mono through WebClient to represent a request body and returned response as subscribable tasks.
How it connects
Connects Mono with Reactor, WebClient, and WebFlux through publisher and subscription roles.

Also explained in

Compare how 3 books explain Mono →

Related concepts

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