4 Handling communications

 

This chapter covers

  • Exposing and consuming APIs using the REST paradigm
  • GraphQL as an alternative to the REST paradigm
  • gRPC and Protocol Buffers as yet another way to expose and consume APIs

Microservices applications require a lot of network communication between the various parts. Recall that we plan to develop a system comprising the Users, Reservation, Rental, Inventory, and Billing services. All of these services need to exchange information between them. This communication can be synchronous, where an application that requires some data from another system makes a network call and waits for the result, or asynchronous, where the requesting service receives a notification of the result when it completes. In this chapter, we focus on synchronous communication since it still is the primarily utilized method of network communication in the microservices architecture. Specifically, we will learn how Quarkus makes it very easy to develop client and server applications that produce and consume data over the following protocols:

  • Hypertext Transfer Protocol (HTTP) with representational state transfer (REST)
  • GraphQL
  • gRPC

REST is a ubiquitous paradigm that probably doesn’t require a long introduction. Quarkus makes it easy to design your own REST API with a simple annotation-based model. We also learn how to write the client side—it’s just as easy since you can use the same annotations on the client.

4.1 Developing REST-based Quarkus applications

4.2 Car rental Reservation service

4.2.1 Checking car availability

4.2.2 Making a reservation

4.2.3 Experimenting with the exposed REST API using the Swagger UI

4.3 Using the REST client

4.4 Developing Quarkus applications with GraphQL

4.5 Car Rental Inventory service

4.5.1 Exposing the Inventory service over GraphQL

4.5.2 Invoking GraphQL operations using the UI

4.5.3 Reviewing the GraphQL schema

4.5.4 Consuming the Inventory service using a GraphQL client

4.6 Developing Quarkus services with gRPC

4.6.1 Understanding when to use gRPC

4.6.2 Protocol Buffers

4.7 Adding gRPC support to your project