英文:
Can I generate a grpc stub file by referring to an external url?
问题
从上周开始,我开始学习gRPC / protobuf,并且我想找出最佳的微服务架构。其中一个方面是将接口定义语言(IDL)存储库单独分离出来。这样,任何服务都可以生成存根文件,而无需从另一个服务中复制/粘贴proto文件。这种做法可行吗?
英文:
I was start to learning gRPC / protobuf from last week and I wanna find out best architectures for microservices. So one of the things is to have a IDL repository separately. If so, Any service can generate stub files without proto file copy / paste from another service. Is it possible?
答案1
得分: 2
如果我没记错的话,protoc
不支持通过URL引用proto文件,这是不幸的,因为这是一个合理的需求。可能是因为特定语言的代码生成实现支持这一功能。
我建议你将项目的proto文件(可能还包括从它们生成的protoc
代码)发布在一个单独的(proto)仓库中。这样可以促进重用,独立版本控制,并鼓励跨语言使用。
如果proto文件被捆绑在一个包含Golang服务器实现的仓库中,要想仅克隆proto文件以生成Python客户端就更加困难。
英文:
IIRC protoc
does not enable referencing protos via URL which is unfortunate as it's a reasonable requirement. It's possible that language-specific implementations of the code generation, do enable this.
I recommend you do publish a project's protos (and possibly cache code protoc
-generated from them) in a separate (proto) repo. This facilitates reuse, independent versioning and encourages cross-language use.
If protos are bundled in e.g. a repo including a Golang server implementation, it's more difficult to just clone the protos in order to generate e.g. a Python client.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论