首页 > 其他 > 详细

grpc

时间:2018-12-20 23:12:46      阅读:185      评论:0      收藏:0      [点我收藏+]

安装

pip install grpcio
pip install grpcio-tools

定义proto协议文件

xxx.proto

syntax = "proto3";
package face;

// The greeting service definition.
service FaceServer {
  // Sends a greeting
  rpc FaceRequest (RequestFormat) returns (ReplyFormat) {}
}

// The request message containing the user‘s name.
message RequestFormat{
    string service_function = 1;
    string function_params = 2;
}

// The response message containing the greetings
message ReplyFormat{
    string status = 1;
    string data = 2;
}

对proto文件进行编译

$ python -m grpc_tools.protoc -I../../protos --python_out=. --grpc_python_out=. ../../protos/helloworld.proto


# 命令解析(. 为执行命令所在的文件夹位置)
python -m grpc_tools.protoc -I

#指定proto所在的文件夹
../../protos

# 请求和响应的数据格式类的位置helloworld_pb2.py
--python_out=./

# 服务端、客户端类的位置helloworld_pb2_grpc.py
--grpc_python_out=./

# 指定具体proto文件的位置
../../protos/hello.proto

grpc

原文:https://www.cnblogs.com/dancingsnow/p/10152949.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!