There is a situation where I need to implement 2 versions of the grpc API on my server. How can I do this?
syntax = "proto3";
package greet.v1;
will help me to add versioning to my pb2 autogenerated files, but I completely don't understand how to combine both pb2(v1 and v2) on the same server. Maybe anyone has an example of grpc versioning in Python? Or maybe it's a bad practice to use 2 versions in one server and I should use another pod for a new grpc version..
Apologies for the weak example.
It's possible to run a single server with multiple (versions of) services and there's no intrinsic reason why you wouldn't want to do this.
Just as you can share Python classes|methods (e.g. using packages), you can share the implementation details of classes for your servicers.
It's good practice to keep implementations of stubs in distinct packages (partly because of the way gRPC|protobuf use packages in Python) but as a way to (more accurately) reflect the structure and versioning of your code.
For example, ideally, you'd not want to change the server implementation (simplistically reflected here by
main.py) when you have minor version changes in v1 or v2; you'd prefer to simply bump therequirements.txtpackages.I'm assuming that you've breaking changes between v1 and v2 and have similar in the following:
protos/greet/v1/greet.proto:protos/greet/v2/greet.proto:And:
requirements.txt:And:
main.py:And:
Enumerate v1 Method
Invoke v1 Method
Enumerate v2 Method
Invoke v2 Method