Building Reactive Java Applications with Spring Framework

If you’re a Java developer who uses the Spring ecosystem, you’ve probably seen the Spring Pet Clinic. In this workshop, we will walk you through a new reactive implementation of the Pet Clinic backend that uses Spring WebFlux and Apache Cassandra® (via DataStax Astra DB).

The cloud-native database-as-a-service built on Cassandra fits the highly concurrent, non-blocking nature of our reactive application. We’ll do all of our work in the cloud with Gitpod’s open-source, zero-install and collaborative development environment.

Authentication With Remote LDAP Server in Spring WebFlux

In my previous article, we covered authentication and authorization with remote LDAP servers in Spring Web MVC. Since base concepts are the same, some sections are unavoidably the same in these two articles and they are kept in both articles in order to create a seamless reading experience for WebFlux and MVC learners. 

In this article, we will develop a reactive Spring Boot project and integrate into remote LDAP through Spring Security. In addition, we will perform authentication (auth) and authorization (autz) operations over JWT (JSON Web Token) for the APIs we will open. 

WebFlux and Spring Data Example for Java Records

Traditionally, Java developers have depended on constructors, accessors, equals(), hashCode(), and toString() to define classes for basic aggregation of values. However,  this is an error-prone approach that adds little value and diverts attention away from modeling immutable data. Java records were initially offered as a preview in JDK 14 to simplify writing data carrier classes. The second preview was released in JDK 15, and the final version in JDK 16. The JDK Enhancement Proposal JEP 395 has a summary of this history.

While code generators can help reduce boilerplate code, the Java record proposals focus on the semantics of the code. Let's look at the characteristics and benefits of Java records and how to use them to develop a REST API and query a database.

WebFlux: Reactive Programming With Spring, Part 3

This is the third part of my blog series on reactive programming, which will give an introduction to WebFlux — Spring’s reactive web framework.

1. An Introduction to Spring Webflux

The original web framework for Spring — Spring Web MVC — was built for the Servlet API and Servlet containers.

Error Handling in Spring Webflux

The topic of error handling in web applications is very important. From a client perspective it is essential to know on how was the request proceeded and in case of any error is crucial to provide to the client a valid reason, especially if the error was due to the client’s actions. There are different situations, when notifying callers about concrete reasons is important – think about server-side validations, business logic errors that come due to bad requests or simple not found situations.

The mechanism of error handling in Webflux is different, from what we know from Spring MVC. Core building blocks of reactive apps – Mono and Flux brings a special way to deal with error situations, and while old exception-based error handling still may work for some cases, it violates Spring Webflux nature. In this post I will do an overview of how to process errors in Webflux when it comes to business errors and absent data. I will not cover technical errors in this article, as they are handled by Spring framework.

Getting Started With Spring Cloud Gateway

In this article, we will integrate spring cloud gateway with a microservice-based architecture application using spring cloud. In the process, we will use spring cloud gateway as a gateway provider, Netflix Eureka as a discovery server, with circuit breaker pattern using Netflix Hystrix.

Let's quickly get started with the implementation of it.