Asynchronous Communication for Microservices

In the previous chapter, we created a Forecast service that consumes Location and Temperature services to produce results showcasing the weather forecast. We also explored ways to register and discover services that are available on the network. All of that is very easy and straightforward. Very often, however, you'll need to optimize the communication between services, which is where asynchronous communication can be helpful.

In this chapter, we'll discuss how we can introduce asynchronous processing and communication to our services. There are many levels of asynchronous communication, from simpler ones to more robust and complex ones. Complexity has its own costs, therefore we'll start by adding asynchrony to the communication in a couple of small steps.

We'll modify the Forecast REST service to call other services more effectively, calling them in parallel and receiving their responses asynchronously when they are ready. Then, we'll modify it further to return a stream of data via the Server-Sent Events (SSE) protocol so that the data can be processed immediately when available.

We will discuss WebSocket-based communication and look into the details of message-oriented and queue-based communication. We will also cover point-to-point and publisher-subscriber patterns of communication.

In a nutshell, the following topics will be covered in this chapter:

  • Speeding up services with a Reactive API
  • Streaming responses with SSE
  • Two-Way Asynchronous services with WebSocket
  • Decoupling services with Message-Oriented Middleware

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.188.121