In the previous blog post, we covered the basics of how to use Keycloak with Spring boot. In this blog post, we will explore Role-based Access Control to Rest API with Keycloak. So let’s get started! Imagine we have a microservice for a Research Journal Management System that can serve users with two types of…
Read More Role-Based Access Control to REST API with Keycloak
Spring Boot is a popular framework for building Java-based web applications. It provides a simple and efficient way to build, deploy and run Java applications quickly. In this tutorial, we’ll explore the framework’s basics, including its features, advantages over the Spring Framework, and how to get started with creating your first application using it. Whether…
Read More Spring Boot: Getting Started Guide
In this tutorial, you will learn how to use Jackson ObjectMapper with Spring Boot application to serialize and deserialize Java objects. Overview In today’s time, the JSON format is one of the most popular formats to transfer and exchange data on the world wide web. Almost all RESTful web services support JSON as input and output…
Read More Jackson ObjectMapper Tutorial
Internationalization (i18n) is the process of making your application and services capable of delivering in different languages. This tutorial will show how the Spring Boot framework manages internationalization. Overview The internet has become global, implying that any application or website can target millions of users worldwide. Although half of the world’s population may have access…
Read More Spring MVC Internationalization Tutorial
<dependency> <groupid>io.projectreactor</groupid> <artifactid>reactor-test</artifactid> <version>3.1.0.RELEASE</version> <scope>test</scope> </dependency> class ReactiveJavaTutorialTest { @Test public void testFlux() { //Create a Flux Flux <Integer> fluxToTest = Flux.just(1, 2, 3, 4, 5); // Create a test StepVerifier.create(fluxToTest) .expectNext(1) .expectNext(2) .expectNext(3) .expectNext(4) .expectNext(5) .expectComplete() // we expect Flux to complete after sending the number 5 which is the last element .verify(); }…
Read More Testing with StepVerifier in Project Reactor
class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.fromIterable( new ArrayList<>(Arrays.asList(“New York”, “London”, “Paris”, “Toronto”, “Rome”))); cities.log().subscribe(); } } Output: INFO 6832 — [ main] reactor.Flux.Iterable.1 : | onSubscribe([Synchronous Fuseable] FluxIterable.IterableSubscription) INFO 6832 — [ main] reactor.Flux.Iterable.1 : | request(unbounded) INFO 6832 — [ main] reactor.Flux.Iterable.1 : | onNext(New York) INFO…
Read More Implementing Backpressure in Project Reactor
class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.just(“New York”, “London”, “Paris”, “Amsterdam”) .map(String::toUpperCase) .filter(cityName -> cityName.length() <= 8) .map(cityName -> cityName.concat(” City”)) .log(); cities.subscribe(); } Output: INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | onSubscribe([Fuseable] FluxMapFuseable.MapFuseableSubscriber) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | request(unbounded) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : |…
Read More subscribeOn and publishOn operators in Project Reactor
class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.just(“New York”, “London”, “Paris”, “Amsterdam”) .map(String::toUpperCase) .filter(cityName -> cityName.length() <= 8) .map(cityName -> cityName.concat(” City”)) .log(); cities.subscribe(); } } INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | onSubscribe([Fuseable] FluxMapFuseable.MapFuseableSubscriber) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | request(unbounded) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : |…
Read More Reactor Execution Model – Threading and Schedulers
This tutorial is about creating Lambda functions from Spring Cloud Functions. Spring Cloud Functions provide a way to implement the business logic via functions and decouple code development from the runtime target. Hence, the developer can focus solely on the implementation of logic. The developer need not worry about the target endpoint type, connectivity, integration,…
Read More Create AWS Lambda Functions from Spring Cloud Functions
class ReactiveJavaTutorial { public static void main(String[] args) throws InterruptedException { Flux<String> netFlux = Flux.fromStream(ReactiveJavaTutorial::getVideo) .delayElements(Duration.ofSeconds(2)); // each part will play for 2 seconds // First Subscriber netFlux.subscribe(part -> System.out.println(“Subscriber 1: ” + part)); // wait 5 seconds before next Subscriber joins Thread.sleep(5000); // Seconds Subscriber netFlux.subscribe(part -> System.out.println(“Subscriber 2: ” + part)); Thread.sleep(60000); }…
Read More Hot and Cold Publishers in Project Reactor
In this tutorial, we are going to see how we can use the AWS API Gateway as a trigger to an AWS Lambda function. This tutorial requires you to be familiar with building and deploying Serverless Applications with AWS Lambda. Prerequisite: Build and Deploy a Serverless Spring Boot Web Application with AWS Lambda Firstly, add…
Read More Trigger a Lambda Function Using AWS API Gateway
Build and deploy a Serverless Spring Boot Web Application with AWS Lambda This is a tutorial about creating a basic AWS Lambda function in Java using the Spring framework and requires you to have an active AWS account. If you don’t, go ahead and create one. Lambda is the serverless compute service provided by the…
Read More Build and deploy a Serverless Spring Boot Web Application with AWS Lambda
class ReactiveJavaTutorial { public static void main(String[] args) { Mono.just(“data1”) .concatWith(Flux.error(new RuntimeException(“Exception occurred.”))) .doOnError(ex -> System.out.println(“LOG: Exception caught: ” + ex)) .retry(3) //retry 3 times in case of an error .log() .subscribe(); } } Output: reactor.Flux.Retry.1 : onSubscribe(FluxRetry.RetrySubscriber) reactor.Flux.Retry.1 : request(unbounded) reactor.Flux.Retry.1 : onNext(data1) LOG: Exception caught: java.lang.RuntimeException: Exception occurred. reactor.Flux.Retry.1 : onNext(data1) LOG: Exception…
Read More RetryFailed Operation in Project Reactor
class ReactiveJavaTutorial { public static void main(String[] args) { Flux.just(2, 7, 10) .concatWith(Flux.error(new RuntimeException(“Exception occurred”))) .concatWith(Mono.just(12)) .log() .subscribe(); } } Output: reactor.Flux.ConcatArray.1 : onSubscribe(FluxConcatArray.ConcatArraySubscriber) reactor.Flux.ConcatArray.1 : request(unbounded) reactor.Flux.ConcatArray.1 : onNext(2) reactor.Flux.ConcatArray.1 : onNext(7) reactor.Flux.ConcatArray.1 : onNext(3) reactor.Flux.ConcatArray.1 : onError(java.lang.RuntimeException: Exception occurred) reactor.Flux.ConcatArray.1 : java.lang.RuntimeException: Exception occurred at com.example.demo.DemoApplication.main(DemoApplication.java:14) ~[classes/:na] You can see that element…
Read More Handling Exceptions in Project Reactor
class ReactiveJavaTutorial { public static void main(String[] args) { Flux.just(“data1”, “data2”, “data3”) .doOnSubscribe(subscription -> System.out.println(“Subscription: ” + subscription)) .subscribe(); } } Output: Subscription: reactor.core.publisher.FluxArray$ArraySubscription@72bca894 doOnNext() method class ReactiveJavaTutorial { public static void main(String[] args) { Flux.just(“data1”, “data2”, “data3”) .doOnNext(data -> System.out.println(“Data: ” + data)) .subscribe(); } } Output: Data: data1 Data: data2 Data: data3 doOnComplete()…
Read More doOn Callbacks in Project Reactor