How gRPC can be a good tool for asynchronous communication
In distributed applications, it's common for one microservice to outsource a large chunk of work to another microservice in an asynchronous fashion. Perhaps the task would take a relatively long time to execute, so you wouldn't want to wait for a response. All you would be interested in is that the task has been successfully initiated.
gRPC allows you to do this. Streaming calls, which we covered earlier, aren't only suitable to pass collections—they can also be used for asynchronous task execution.
In the following example, we will add another service to our StatusMicroservice
application. This service will use two streaming endpoints and will mimic the execution of long-running tasks of two different types. We will then add a new controller to our ApiGateway
project to initiate asynchronous communication with the server.
Adding client-streaming and server-streaming gRPC endpoints
First,...