Published by Packt
Build cloud-ready, reactive systems with Spring 5.1 and Project Reactor.
The code for this repository is under development 👷
All code samples should run on any operating system where the appropriate Java runs. Some examples require Docker Engine.
There is no hard requirement for OS. However, examples use JDK8 and later, Docker Engine 18.06 and later, and also download native executables (embedded MongoDB). Consequently, for successful execution, all software described above should work on your OS.
Tested operation systems: MacOS High Sierra, Windows 10.
All examples were developed with JDK8 and tested to be compatible with JDK11. Because of the significant changes introduced by JDK11, some examples may display warnings or run only on JDK8.
To install JDK8, please refer to these instructions: https://jdk.java.net/8
To install JDK11, please refer to these instructions: https://jdk.java.net/11
A couple of examples assume running Docker Engine to start supporting services (MongoDB, PostgreSQL, Prometheus, etc.)
Only Chapter 10's example requires running Docker commands manually, other examples do automatic service provisioning.
To install Docker Engine on your PC, please follow the official instructions: https://docs.docker.com/install
All examples use Gradle build system, so they are not IDE dependent. However, we recommend using a free version of IntelliJ IDEA for a seamless exploration of the provided examples. We recommend using the latest version of IntelliJ IDEA as it has better support for JDK11.
The Community Edition of IntelliJ IDEA may be downloaded here: https://www.jetbrains.com/idea/download
Many examples use a handy the Lombok library (https://projectlombok.org/) which require annotation processing. Consequently, please install IntelliJ Lombok plugin (https://github.com/mplushnikov/lombok-intellij-plugin).
Also, please enable annotation processing in IDE (Preferences
-> Build, Execution, Deployment
-> Complier
-> Annotation Processors
-> Check Enable annotation processing
).
When IDE is installed and configured, you may open this project as Gradle project.
Then, please define JDK for the project (File
-> Project Structure
-> Project Settings
-> Project
-> Project SDK
).
Then, rebuild all modules of the project (Build
-> Rebuild Project
).
Now, you may explore and run all examples.
All code in this repository is for demonstration purposes and, consequently, often oversimplified. Also, the code in this repository is not production ready and may require some improvements and additional testing.
Contains the following examples:
ChapterFirstApplication
- a web application that demonstrates the blocking communication approach.imperative.OrdersService
- a console application that demonstrates the synchronous, blocking approach for components interactions.callbacks.OrdersService
- a console application that demonstrates the callback-based approach for components interactions.futures.OrdersService
- a console application that demonstrates theFuture
based approach for components interactions.completion_stage.OrdersService
- a console application that demonstrates theCompletionStage
based approach for components interactions.
- Module unit tests show examples of the Observer pattern and reactive workflows with RxJava 1.
pub_sub_app.Application
- a web application that demonstrates how Spring 4 enables asynchronous execution withApplicationEventPublisher
and SSE.rx_app.Application
- a web application that demonstrates how Spring 4 enables asynchronous execution with RxJava 1.x and SSE.rx_app_no_logs.Application
- a web application that demonstrates how Spring 4 enables asynchronous execution with RxJava 1.x and SSE.
conversion_problem
- a web application (with corresponding unit tests) demonstrates how to convert different types of futures.async.vs.reactive
- unit tests compares the asynchronous and reactive approached (Publisher
asCompletableFuture
,CompletableFuture
asPublisher
).news-service.NewsServiceApp
- th console application that demonstrates custom implementation of Reactive Streams' interfaces (Publisher
,Subscriber
,Processor
). Works with JDK8, fail with JDK11.news-service
unit tests show how to test custom implementation of Reactive Streams with TCK. Tests are based on TestNG. Works with JDK8, may fail with JDK11. Tests may run long!jdk9
- a console application that demonstrates how to adaptreactive-streams
types to Java Flow API. This application requires at least JDK9.push.vs.pull
- classes and unit tests that demonstrate different approaches for data retrieval (pull, batched pull, push, push-pull).rxjava-reactivestreams-ratpack.LogServiceApplication
- a web application that demonstrates the power of Reactive Streams for integration of reactive libraries (Spring, Ratpack, RxJava, etc.). Works with JDK8, may fail with JDK11.vert.x.VertxDemoApp
- a web application that demonstrates how Verte.x integrates with Reactive Streams.
- Module unit tests show examples of reactive workflows with Project Reactor.
- Module unit tests show how Spring's reactive adapters work.
Chapter5ReactiveApplication
- web reactive application that simulates IoT sensor (SSE, MongoDB write, MongoDB read).
section-01-jdbc
- a blocking console application that demonstrates Jdbi library, Spring JDBC and Spring Data JDBC (runs embedded H2 database).section-02-jpa
- a blocking console application that demonstrates Spring Data JPA (runs embedded H2 database).section-03-mongo
- a blocking console application that demonstrates Spring Data MongoDB (runs embedded MongoDB)section-04-rx-mongo
- a reactive console application that demonstrates reactive Spring Data MongoDB (runs embedded MongoDB).section-05-rx-mongo-tx
- unit tests that demonstrate how reactive transactions work with MongoDB 4 (runs MongoDB cluster in Docker).section-06-r2dbc
- a reactive console application that demonstrates how Spring Data JDBC and R2DBC work together (runs PostgreSQL in docker).section-07-rx-webflux
- a reactive web application (SSE) that simulates simple chat application (embedded MongoDB).section-08-rx-dbs
- code samples that demonstrate different types of reactive repositories (MongoDB, Cassandra, Couchbase, Redis).section-09-rx-sync
- a console application that demonstrates how to wrap blocking JPA repository into reactive repository (runs embedded H2 database).section-10-rxjava2-jdbc
- a console application that demonstrates how to use therxjava2-jdbc
library for reactive communication over blocking JDBC (runs embedded H2 database).
DemoApplication
- a web application used for testing with a reactive test framework.- Module unit tests demonstrate how to verify reactive applications with
WebTestClient
(including security).
This sample depicts a reactive application based on Spring Boot 2 and WebFlux with all required infrastructure for operational monitoring.
Prometheus pulls metrics, Grafana has a simple dashboard with app metrics, Zipkin gathers traces.
- Application itself:
- Reactive Web App (with Spring Boot Admin)
- Database: MongoDB (used only for health checks)
- Monitoring infrastructure:
- Prometheus
- Grafana
- Zipkin
To start services run the following command:
docker-compose -f chapter-10/docker/docker-compose.yml up -d
To stop services run the following command:
docker-compose -f chapter-10/docker/docker-compose.yml down
To start the application, run class
org.rpis5.chapters.chapter_10.Chapter10CloudReadyApplication
.
- Reactive Web Application: https://localhost:8080
- Spring Boot Admin 2.0: https://localhost:8090/admin (authentication disabled)
- Prometheus: https://localhost:9090
- Grafana: https://localhost:3000 (user:
admin
, password:admin
) - Zipkin: https://localhost:9411
Application web page:
Spring Boot Admin:
Zipkin report page:
Application monitoring dashboard provided by Grafana over Prometheus' metrics:
Your feedback is important for us, so do not hesitate creating issues if some examples do not work with your environment.
Also, please star of fork this repository if you find it useful!
Thanks!