Reactive Client APIs Introduction
Asynchronous programming in JAX-RS enables clients to unblock certain threads by pushing work to background
threads which can be monitored and possibly waited on (joined) at a later time. This can be accomplished in JAX-RS
by either providing an instance of InvocationCallback
or operating on the result of type
Future<T>
returned by an asynchronous invoker or some combination of both styles.
Using InvocationCallback
enables a more reactive programming style in which user-provided code
activates (or reacts) only when a certain event has occurred. Using callbacks works well for simple cases, but the
source code becomes harder to understand when multiple events are in play.
To address the requirement of greater readability and to enable programmers to better reason about asynchronous
computations, Java 8 introduces the a new interface called CompletionStage
that includes a large
number of methods dedicated to managing asynchronous computations.
JAX-RS 2.1 defines a new type of invoker called RxInvoker
, as well a default implementation of this
type called CompletionStageRxInvoker
that is based on the Java 8 type CompletionStage
.
Description of the Example
This example demonstrates the reactive client APIs in JAX-RS 2.1. In this example, we illustrate how reactive
JAX-RS 2.1 client integrates seamlessly with asynchronous JAX-RS resources and CompletableFuture.
Use This Example
Get Current User