Search code examples
.netprotocol-buffersgrpc.net-5protobuf-net

GRpc protobuf generic client runtime


i'm trying to create a dotnet core 5 app with multiple GRpc clients/servers generated from protobuf files. One of the servers should act like a "master" to handle the life cycle of the whole app from one endpoint.

All clients implements a common interface

public interface IClient {
    public Task PingAsync()
}

And one of the service protobuf. All services protobuf have this Ping method.

syntax = "proto3";

import "google/protobuf/empty.proto";

package services;

service Service1{
  rpc Ping(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  ...More specific methods...
}

I would like the master server to be able to communicate with all the services with clients as IClient. The only information that the Master has is the url/port of each other GRpc server.

Is there a way to create a sort of "base class" for clients which the launcher will be able to use. Something like

var client = new GenericClient(url, port);
await client.PingAsync();

so servers keep having only one proto file.

Servers already exist and would want to make not too much modifications if possible. Especially, i would like to have only one proto file by server if possible.

Because servers already exists, they already using this Ping method to communicate between them so i would like to keep using it if possible.


Solution

  • After some discussion with @JonSkeet, there is no "simple" solution the cover everything that i want to do.

    The best workaround is to create a dedicated Ping GRpc service.

    This service will then be added as GRpc service in each server. So the Master can instantiate a Ping client for each Server.