Java Magazine, Jan/Feb 2018
Forecast Service ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 19 reactive programming rx get CompletionStage T is a new interface introduced in Java 8 and it represents a computation that can be a stage within a larger computation as its name implies Its the only reactive portion of Java 8 that made it into the JAX RS After getting a response instance I can just invoke thenAcceptAsync where I can provide the code snippet that would be executed asynchronously when the response becomes available such as shown in Listing 4 Listing 4 response thenAcceptAsync res Temperature t res readEntity Temperature class do stuff with t Adding Reactive Goodness to a REST Endpoint The reactive approach is not limited to the client side in JAX RS its also possible to leverage it on the server side To demonstrate this I will first create a simple scenario where I can query a list of locations from one endpoint For each location I will make another call to another endpoint with that location data to get a temperature value The interaction of the endpoints would be as shown in Figure 1 Location Service Temperature Service Figure 1 Interaction between endpoints
You must have JavaScript enabled to view digital editions.