Ensuring that your connection remains alive
Your application, which acts as a gRPC client, might experience prolonged periods of idleness where no gRPC calls are made to the server. In this period, your connection to the server may get interrupted. Therefore, while reusing a gRPC channel is good for performance, you need to ensure that the channel can still be used every time you need to rely on it.
Fortunately, ensuring that the connection remains alive is relatively easy to implement. To some extent, this functionality will already be configured by default. But you can also fine-tune it to suit your needs.
Setting up keep-alive pings on the gRPC client
Inside the ConcurrencyController
class of the ApiGateway
application, locate the GetDataFromMultipleConnections
method. Inside this method, replace the initialization of the channel
variable with the following code:
using var channel = GrpcChannel.ForAddress(serverUrl, new GrpcChannelOptions { ...