AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

gRPC: Document strategies for sharing proto files between apps

Open StingyJack opened this issue 3 years ago • 9 comments

Copy the Protos\greet.proto file from the gRPC Greeter service to the gRPC client project.

No, really, please just say how the client can utilize the same service definition or its like representation - without requiring that we maintain two or more copies of the definition. Every other web service has had this kind of ability (wsdl, wcfmex/service contract, swagger/openapispec, etc). This tutorial should be showing us noobs the correct and practical (without having to rely on object remappers?) way.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

StingyJack avatar Mar 28 '21 13:03 StingyJack

A doc page that discusses strategies for sharing proto files would be useful. It is a common topic.

JamesNK avatar May 16 '21 00:05 JamesNK

@JamesNK, do we have anything internally or externally that would help me follow the best practice we would recommend? Maybe a rough outline of what we would recommend?

Move the proto in its own repository? Exposing the proto in some sort of restricted endpoint?

Would this be a pri 1 topic? Seems like it would.

wadepickett avatar Apr 14 '22 18:04 wadepickett

FWIW, I chose to expose the proto files on the service with a static file handler in a browsable "directory". Consumers still need to auth to get to any of the services they represent.

Sticking it in a separate repo still means file copies when we need to use it.

StingyJack avatar Apr 14 '22 22:04 StingyJack

I don't have any content for this at the moment. It's quite complex, but not something I have needed to deal with when implementing gRPC. I'd need to go off and research.

JamesNK avatar Apr 14 '22 23:04 JamesNK

I just made a Data project, that has my proto in it, and told it to provide both GrpcServices with:

  <ItemGroup>
    <Protobuf Include="Protos\greet.proto" GrpcServices="Client,Server" />
  </ItemGroup>

Then you can make the Server and Client project depend on your Data project, and avoid duplicating the proto.

KSRandom avatar Apr 30 '22 20:04 KSRandom

@KSRandom that may work if callers are also .net and are within your scope/org/control/etc.

StingyJack avatar May 02 '22 01:05 StingyJack

Moving to next doc sprint and will kick off once we have an outline.

Notes: A very common scenario to address as a priority: "Splitting message and services across files and then import files into each other, for sharing files in their app. Docs to help this would be what the right path is when importing and where proto tooling looks for these files."

Cross-app proto file sharing solutions that the community is using (random order and just rough ideas to think about for the outline):

  • Share the protocol buffers in into a centrally used repository.
  • Host as static content files in a browsable directory from the running service.
  • Packaging generated code from protocol buffers into libraries.
  • Exposing protocol buffers through a REST endpoint
  • grpc/server-reflection.md at master · grpc/grpc (github.com)

Next step: @JamesNK approves an outline to work on for this.

wadepickett avatar May 18 '22 22:05 wadepickett

@wadepickett - add one to your outline for "host as static content files in a browsable directory from the running service"

StingyJack avatar May 22 '22 18:05 StingyJack

Using Connected Services can easily configure the proto reference of other projects, and you can delete the link in the project file. However, this can only refer to the proto of the local file, not the proto of the project. Of course, there is nothing for the relative path of the same solution. the difference

SmRiley avatar Aug 19 '22 08:08 SmRiley

if you wanna use Client and Server classes, should use Both keywork in GrpcServices argument

armintodev avatar Nov 11 '23 08:11 armintodev

@arminatwork - The point is that we dont want to use them in the same code. My team (that is skilled with .net) may be asked to build a gRPC service that serves Widgets. We do this and deploy it and test it and its working. Other teams in the same org (or externally) that could be skilled with another language like Python may need to consume our Widget service.

The simplest thing to do is to share the definition - the proto file - so the clients can be sure to meet it in whatever way is easiest for them. What's the best way to share this definition? Email is cumbersome at best. Referring to the one in the repository could be problematic if its different from what is deployed.

This isn't a unique problem but it is kind of odd that its one that doesnt already have a solution considering prior and current web service technologies have this defined as part of them (WSDL for SOAP, OAS for REST Api)

StingyJack avatar Nov 11 '23 20:11 StingyJack