Spring in Action Notes

Personal notes from going through Spring in Action 6th Edition.

Part 1: Getting started with Spring

flowchart LR

subgraph Spring application context
A[Inventory Service] -- Injected into --> B[Product Service]
end

pom.xml File

Handling web requests

Spring Boot DevTools

Hand development-time tools, including:

Spring Boot autoconfiguation library

When the application starts, Spring Boot autoconfiguration performs the following tasks:

MVC

Part 3: Reactive Spring

Reactive programming

Reactive Streams spec

A Publisher produces data that is sends to a Subscriber per a Subscription

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

Once a Subscriber has subscribed, it can receive events from a Publisher. Those events are sent over the methods on the Subscriber interface.

public interface Subscriber<T> {
  void onSubscribe(Subscription sub);
  void onNext(T item);
  void onError(Throwable ex);
  void onComplete();
}

The first call to a Subscriber is when the Publisher calls onSubscribe(). It passes a Subscription object to the Subscriber, which allows the Subscriber to manage the Subscription.

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

The Subscriber will call request with the number of data it wants to receive (backpressure). After it has received the given count, it can call request again. It can call cancel() if it no longer wants to receive items. onNext will be called for each item given. When all data has been sent, the Publisher will call onComplete.

A Processor/Transformer is a combination of a Publisher and a Subscriber.

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

As a Subscriber, a Processor will receive data and process it in some way. Then is will switch and act as a Publisher to publish the results to its Subscribers.

Project Reactor is an implementation of the React Streams specification that provides a functional API for composing Reactive Streams.

Developing reactive APIs