2017-03-07 63 views
1

我有以下原始文件,將生成一個_pb2.py文件在python中使用。gRPC和Beta gRPC類有什麼區別?

syntax = "proto3"; 
service Calculator { 
    rpc Add (AddRequest) returns (AddReply) {} 
} 
message AddRequest{ 
    int32 n1=1; 
    int32 n2=2; 
} 

message AddReply{ 
    int32 n1=1; 
} 

_pb2.py protoc將產生:

... 
class CalculatorServicer(object): 
    def Add(self, request, context): 
    context.set_code(grpc.StatusCode.UNIMPLEMENTED) 
    context.set_details('Method not implemented!') 
    raise NotImplementedError('Method not implemented!') 

class BetaCalculatorServicer(object): 
    def Add(self, request, context): 
    context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) 
... 

我想知道這兩個類之間(CalculatorServicer VS BetaCalculatorServicer)和它們的用法區別。

我見過使用第一個類的代碼和使用第二個的代碼。

回答

0

您應該使用不合格代碼元素(尤其是_pb2_grpc.py文件中的代碼元素),而不是_pb2.py文件中的測試代碼元素。如果您使用最新版本的代碼生成器生成_pb2.py_pb2_grpc.py文件(請嘗試使用絕對最新的grpcio-tools,當前爲1.1.3),您應該看到doc strings on the Beta code elements in the generated code describing them as deprecated and to be removed in the future

Our examples顯示生成的_pb2_pb2_grpc模塊的當前預期用途。