WebFlux functional reactive services demo presented by IPT-Intellectual Products & Technologies @jProfessionals 2018
This is a demo application, which shows how to develop functional reactive (micro-)services using Spring 5 WebFlux, Spring Boot 2.0, Spring Data reactive repositories, MongoDB, reactive Spring Security and more.
You can find links to the presentation in this post.
All demos use Gradle for building.
Spring 5 adds a plenty of new features. Following are my favourits:
- Reactive Programming Model
- Spring Web Flux
- Reactive DB repositories & integrations + hot event streaming: MongoDB, CouchDB, Redis, Cassandra, Kafka
- Testing improvements – WebTestClient (based on reactive WebFlux WebClient)
- JDK 8+ and Java EE 7+ baseline - see the
reactive-quotesdemo for Java 9 example - Kotlin functional DSL
- Be sure to configure
JAVA_HOMEenvironment variable to point to JDK 9, andPATHto includebinsub-folder of JDK 9 (for Windows). For Linux use something likesudo update-java-alternatives --listandsudo update-java-alternatives --set [JDK/JRE name e.g. java-9-oracle]to choose the java 9. - Build and run the Spring Boot-Gradle application (
reactive-streaming-demosmodule) - e.g. rungradle bootRunfrom thereactive-streaming-demosfolder. The application main class isorg.iproduct.demos.spring.streamingdemos.ReactiveStreamingDemosApp. - Open http://localhost:9000/ for Java Processes CPU Profiling demo (using novelties in Java 9 Process API:
ProcessHandleandProcessInfoclasses), and http://localhost:9000/quotes.html for Reactive Option Quotes demo respectively in your browser.
Provides information about runiiing Java processes and streaming data about their CPU ussage. Second demo provides streaming data about fictional options quote prices. All data is purely fictional - NO real stock prices are quoted :):
| Method | Path | Description | JSON | SSE Streaming |
|---|---|---|---|---|
| GET | /api/processes | List all currently running Java processes | * | |
| SSE | /api/cpu | Get realtime stream of CPU consumption for all Java processes | * | * |
| SSE | /api/quotes | Get fictional options quote prices in realtime | * | * |
- Be sure to configure
JAVA_HOMEenvironment variable to point to JDK 8, andPATHto includebinsub-folder of JDK 8 (for Windows). For Linux use something likesudo update-java-alternatives --listandsudo update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]to choose the java 8. - Install (if not already installed) latest version of MongoDB, create <local_database_folder>, and start MongoDB - e.g. run
mongod --dbpath="<local_database_folder>". - Build and run the Spring Boot-Gradle application (
webflux-usersmodule) - e.g. rungradle bootRunfrom thewebflux-usersfolder. The application main class isorg.iproduct.demos.spring.manageusers.WebfluxUsersApplication. - Open http://localhost:8080/api/users in your browser - you should be asked to login using BASIC authentication with default admin cedentials - user: admin, password: admin. Should see something like:
[{"id":"","username":"admin","fname":"Default","lname":"Admin","role":"ADMIN","active":true}]. You could use a REST client such asPostmanorcurlto read, create, update and delete users following the standard REST API conventions. - Run the unit tests (does not require server to be started) with:
gradle clean testorgradle clean test --info
Provides CRUD operations for the Users:
| Method | Path | Description | Requires authentication | Admin only |
|---|---|---|---|---|
| GET | /api/users | List all users | * | |
| GET | /api/users/{userId} | Get current account statistics | ||
| POST | /api/users | Create new user | * | |
| PUT | /api/users/{userId} | Update user data | * | |
| DELETE | /api/users/{userId} | Delete existing user | * | * |