Win $20,000. Help build the future of education. Answer the call. Learn more

Workshop: Reactive endpoints with Quarkus on OpenShift

Introduction

In this workshop, you learn how to implement reactive endpoints with Java, Quarkus, and Eclipse MicroProfile. You deploy an end-to-end sample application to Red Hat® OpenShift® on IBM Cloud®. The open source code is available as part of the Cloud Native Starter project.

One key benefit of reactive systems and reactive REST endpoints is efficiency. This workshop describes how to use reactive systems and reactive programming to achieve faster response times. This model saves you money, especially in public clouds where costs depend on CPU, RAM, and compute durations.

This workshop uses a sample application to demonstrate reactive functionality. The simple application displays links to articles and author information. The sample contains a Web-API service with two versions of the /articles endpoint. One uses imperative code and the other one uses reactive code. In this workshop you re-implement a simplified version of the reactive version yourself.

The reactive stack of this sample provides response times that take less than half of the time compared to the imperative stack:

Reactive Imperative
793 ms 1956 ms

If you want to know more details, read the documentation of the performance tests.

The following two architecture diagrams explain the flow between the different components and microservices of the application. In the first diagram:

  • The API Client invokes the Web-API service, which implements a back-end for front-end pattern.
  • The Web-API service invokes the two microservices of Authors and Articles. The Articles service reads data from Postgres.

First flow diagram of the Cloud Native Starter project's sample web application

In this workshop, you deploy the full application as described in the first diagram. But to simplify the workshop, you re-implement a simpler version of the Web-API service, which only invokes the Articles service. This is illustrated in the following diagram:

Second flow diagram of the Cloud Native Starter project's sample web application

Objectives

After you complete this workshop, you’ll understand the following reactive functionality:

  • Reactive REST endpoints via CompletionStage
  • Exception handling in chained reactive invocations
  • Timeouts via CompletableFuture
  • Reactive REST invocations via MicroProfile REST Client

The intention of this workshop is not to explain every aspect of reactive programming, but to explain core reactive principles and to deploy a complete reactive application which you can inspect after the workshop in more detail.

Estimated time

This beginner level workshop will take you about one hour to complete.

Labs

Next steps

After you finish the labs within this workshop, try the Reactive messaging with Quarkus on OpenShift workshop, which focuses on focusses on messaging with Kafka. It uses the same sample Web application as this one.