Learn to write reactive Java microservices with MicroProfile's Reactive Messaging. Learn how to create microservices that are reactive, able to communicate with other microservices and then simultaneously process and receive responses. The application will utilize an outside messaging platform to manage the messages that are exchanged and received between the microservices in the form of streams of events. MicroProfile Reactive Messaging makes easy to create and configure your application to receive, send and process events in a timely manner.
Asynchronous messaging between microservices
The synchronous communications between microservices could be utilized to create dynamic and responsive applications. By separating the requests made by a microservice and the responses it receives it isn't hindered from performing its other tasks while waiting for requested data to be accessible. Imagine asynchronous communications as an eating place. A waiter could appear at your table and serve your food. While you wait for the food to be cooked the waiter will serve other tables and take orders from them too. Once your food is prepared and served, the waiter delivers your food to your table and is then able to serve other tables. If the waiter was to work in a synchronized manner, they have to accept your order, and then wait until they have delivered your food prior to serving other tables. In microservices, a calling a REST client to a different microservice could take a long time because the network may be slow, or the service could be overwhelmed by requests and not be able to respond promptly. In an asynchronous system microservice, the microservice makes an request to a different microservice, and it continues to make additional calls, and take in and process responses until it gets a response to the initial request.
What exactly is MicroProfile Reactive Messaging?
MicroProfile Reactive Messaging is an easy method to send messages, receive, and process messages that are delivered as continuous stream of event. It is as easy as annotating the methods of application beans as well. Open Liberty converts the annotated methods into reactive streams-compatible publishers processors, subscribers, and publishers and connects them to one another. MicroProfile Reactive Messaging offers an API for connecting to a Connector API that allows your methods are able to be linked to other messaging systems that create and consume stream of information, like Apache Kafka.
The system that is described in this article consists of two microservices: inventory and system. Each 15 second, the microservice for system determines and publishes an event that reveals the current system load. The inventory microservice is subscribed to this information in order that it has up-to-date information about the system's current load on the system. The inventory of the current systems is accessible via the /systems REST API endpoint. The system will be created and inventory microservices with the MicroProfile Ractive Messaging.