Book Image

Hands-On Reactive Programming with Reactor

By : Rahul Sharma
Book Image

Hands-On Reactive Programming with Reactor

By: Rahul Sharma

Overview of this book

Reactor is an implementation of the Java 9 Reactive Streams specification, an API for asynchronous data processing. This specification is based on a reactive programming paradigm, enabling developers to build enterprise-grade, robust applications with reduced complexity and in less time. Hands-On Reactive Programming with Reactor shows you how Reactor works, as well as how to use it to develop reactive applications in Java. The book begins with the fundamentals of Reactor and the role it plays in building effective applications. You will learn how to build fully non-blocking applications and will later be guided by the Publisher and Subscriber APIs. You will gain an understanding how to use two reactive composable APIs, Flux and Mono, which are used extensively to implement Reactive Extensions. All of these components are combined using various operations to build a complete solution. In addition to this, you will get to grips with the Flow API and understand backpressure in order to control overruns. You will also study the use of Spring WebFlux, an extension of the Reactor framework for building microservices. By the end of the book, you will have gained enough confidence to build reactive and scalable microservices.
Table of Contents (13 chapters)

What this book covers

Chapter 1, Getting Started with Reactive Streams, explains the Reactive Streams API and introduces the reactive paradigm and its benefits. The chapter also introduces Reactor as an implementation of Reactive Streams.

Chapter 2, The Publisher and Subscriber APIs in a Reactor, explains the Producer and Subscriber APIs and the corresponding Flux and Mono implications of Reactor. It also discusses use cases of Flux and Mono and the respective Sinks. We will also look into Hot and Cold variants of the components.

Chapter 3, Data and Stream Processing, tackles how we can process data generated by a Publisher before it gets consumed by a Subscriber, the possible operations available, and combining them to build a robust stream-processing pipeline. Stream processing also involves converting, pivoting, and aggregating data, and then generating new data.

Chapter 4, Processors, introduces the out-of-the-box processors available in Reactor. Processors are special Publishers, which are also Subscribers, and it is quite important to understand why we need them before jumping into putting one into practice.

Chapter 5, SpringWebFlux for Microservices, introduces SpringWebFlux, a Reactor web extension. It explains the concepts of the RouterFunction, HandlerFunction, and FilterFunction. We will then build a REST-based microservice using Mongo as a store.

Chapter 6, Dynamic Rendering, integrates a templating engine into the REST-based microservice we introduced in the previous chapter, to render dynamic content. It also demonstrates request filters.

Chapter 7, Flow Control and Backpressure, discusses flow control, an important aspect of reactive programming, which is essentially required to control overruns by a fast Publisher. It also discusses various ways to control the complete pipeline processing.

Chapter 8, Handling Errors, as its title suggests, explains how to handle errors. All Java developers are accustomed to the try-catch-finally block of error handling. This chapter translates it for stream processing. It also covers how we can recover from an error and how can we go about generating errors. This is an essential requirement for all enterprise applications.

Chapter 9, Execution Control, looks at the various strategies available in Reactor for processing the built stream. It could be scheduled at some interval or batched in groups, or all operations can be performed in parallel.

Chapter 10, Testing and Debugging, lists ways we can test a stream, because no development is complete without being tested. We will build JUnit tests that will use some of the testing utilities offered by Reactor to create robust tests. The chapter also lists ways to go about debugging asynchronous flows built over Reactor.