In the previous chapter, we created a Spring Boot application that offers a Reactive Web API. We’ll cover in this one how to implement the client’s side using Angular with EventSource and RxJS’ Observable.
Within this chapter, you’ll learn how to develop the Reactive Web Server. We’ll use Spring WebFlux, available since Spring 5, and included from the Spring Boot 2.0 version. We’ll connect to a Mongo database using its reactive driver with Spring Data, also via Spring Boot.
This guide focuses on the capabilities of Spring WebFlux and Spring Boot 2 to create a Reactive Web Application, supported by a code example that you can build step by step.
To avoid dumb, non-realistic examples where Spring is also the client of the Reactive API, you will complete the stack with a client application in Angular 9. To make it reactive, you’ll use Server-Sent Events (SSE) to communicate the backend with the frontend. See the figure below for a quick view of the stack we’ll build.
There are different ways to test your Controller (Web or API Layer) classes in Spring Boot, some provide support to write pure Unit Tests and some others are more useful for Integration Tests. Within this post, I’ll cover the main three test approaches available for Spring: using MockMVC in standalone mode, MockMVC together with SpringRunner, and using SpringBootTest.