🚀 Master the language of AI with our brand new course: "Prompt Engineering for Everyone" Learn more

Offered By: IBM

Creating reactive Java microservices

Learn how to write reactive Java microservices using MicroProfile Reactive Messaging.

Continue reading

Guided Project

Open Liberty

62 Enrolled

At a Glance

Learn how to write reactive Java microservices using MicroProfile Reactive Messaging.

You will learn how to build reactive microservices that can send requests to other microservices, and asynchronously receive and process the responses. You will use an external messaging system to handle the asynchronous messages that are sent and received between the microservices as streams of events. MicroProfile Reactive Messaging makes it easy to write and configure your application to send, receive, and process the events efficiently.

Asynchronous messaging between microservices
Asynchronous communication between microservices can be used to build reactive and responsive applications. By decoupling the requests sent by a microservice from the responses that it receives, the microservice is not blocked from performing other tasks while waiting for the requested data to become available. Imagine asynchronous communication as a restaurant. A waiter might come to your table and take your order. While you are waiting for your food to be prepared, that waiter serves other tables and takes their orders too. When your food is ready, the waiter brings your food to the table and then continues to serve the other tables. If the waiter were to operate synchronously, they must take your order and then wait until they deliver your food before serving any other tables. In microservices, a request call from a REST client to another microservice can be time-consuming because the network might be slow, or the other service might be overwhelmed with requests and can’t respond quickly. But in an asynchronous system, the microservice sends a request to another microservice and continues to send other calls and to receive and process other responses until it receives a response to the original request.

What is MicroProfile Reactive Messaging?
MicroProfile Reactive Messaging provides an easy way to asynchronously send, receive, and process messages that are received as continuous streams of events. You simply annotate application beans' methods and Open Liberty converts the annotated methods to reactive streams-compatible publishers, subscribers, and processors and connects them up to each other. MicroProfile Reactive Messaging provides a Connector API so that your methods can be connected to external messaging systems that produce and consume the streams of events, such as Apache Kafka.
The application in this guide consists of two microservices, system and inventory. Every 15 seconds, the system microservice calculates and publishes an event that contains its current average system load. The inventory microservice subscribes to that information so that it can keep an updated list of all the systems and their current system loads. The current inventory of systems can be accessed via the /systems REST endpoint. You’ll create the system and inventory microservices using MicroProfile Reactive Messaging.

Created by 

The Open Liberty Project team

Estimated Effort

20 Minutes

Level

Intermediate

Language

English

Course Code

GPXX0I4FEN

Tell Your Friends!

Saved this page to your clipboard!

Sign up to our newsletter

Stay connected with the latest industry news and knowledge!