- [Instructor] Let's take a high level look at Project Reactor. Project Reactor provides the reactor foundation for Spring. Project Reactor is a non-blocking reactive library for the JVM. It extensively implements the Reactive Extensions specification so that it is interoperable with other libraries such as ReactiveX and RxJava. If you haven't used reactive libraries before, that might not make a lot of sense to you, so let's go into more detail.
Now, let's take a look at some Project Reactor features. We will be able to handle high latency with better efficiency, for example, a downstream service, or a database call can cause latency. We also minimize resource consumption on potentially blocking operations because waiting is cost-free with a reactive type. This allows your application to handle more load on the same amount of servers.
Let's take a look at the Reactor Project structure. First of all, we have the general Spring framework that you know and love, that provides dependency injection, validation, data binding, and other common functionality. Then, we have Reactor Core that provides a non-blocking reactive streams foundation for the JVM. As you can see, there is some overlap and shared code between Spring and Reactor Core.
Then, we have various input/output libraries, such as, Reactor Kafka, that allows you to integrate with Apache Kafka. Finally, we have add-on modules, such as, reactor logback that offer logback support over asynchronous reactor core processors, and one final note, Project Reactor is very much aligned with RxJava and ReactiveX because they both implement the reactive stream spec.
Developers from both teams actually collaborate quite closely, so the set of operators is very similar. Now, let's review some additional features of the project. Project Reactor provides efficient demand management with backpressure. It also has a lean and easy to use API with only two reactive types. Reactor also integrates directly with the Java 8 functional APIs, such as, CompletableFuture, Stream, and Duration.
We also get composable, asynchronous sequence APIs. You could use a Flux if you have zero to any number of elements, or you could use a Mono, when you'd expect zero or one elements. Reactive types allow applications to serve more requests concurrently with the same amount of hardware. Now finally, let's talk a bit about backpressure. Project Reactor has a deterministic capacity model using a bounded ring buffer.
Operators and processors or any standard Reactive Stream component working on a sequence, will be instructed to flow in only, when these buffers have free room. It will also ensure that operations never block.
- Project Reactor and Reactive Core
- Spring WebFlux
- Reactive Spring Data with MongoDB
- Bootstrapping a reactive web app with Spring Boot 2
- Writing reactive Spring controllers
- Working with Spring reactive data
- Spring reactive unit testing
- Writing tests using the WebTestClient