5 Clients for consuming other microservices

 

This chapter covers

  • MicroProfile REST Client specification
  • Using type-safe interfaces to consume external microservices
  • Customizing the content of headers on the request

Although many microservices require only a database or alternative data services, or process a request within their own process, sometimes a microservice needs to communicate with other microservices to fulfill a request. When shifting from monoliths to microservices, the tendency is toward smaller and leaner microservices, which necessitates more of them. More importantly, many of those smaller microservices will need to communicate with each other to complete a task previously achieved with a single method calling other services inside a monolith. All those previously “in-process” method calls are now external microservice invocations.

This chapter introduces the MicroProfile REST Client and describes how Quarkus implements the specification to provide a type-safe means of interacting with external services. Many possible approaches exist, including Java’s networking library or third-party libraries like OkHttp and Apache HttpClient. Quarkus abstracts away the underlying HTTP transport construction from the developer, enabling them to focus on the task of defining the external service and interacting with the service as if it were a local method invocation.

5.1 What is MicroProfile REST Client?

5.2 Service interface definition

5.2.1 CDI REST client

5.2.2 Programmatic REST client

5.2.3 Choosing between CDI and a programmatic API

5.2.4 Asynchronous response types

5.3 Customizing REST clients

5.3.1 Client request headers

5.3.2 Declaring providers

Summary

sitemap