入门实例
python quickstart
- 安装grpc和代码
- 服务端
- 客户端
- 创建连接
- new 一个 client
- 调用client方法
- 获取返回值
语法
// The greeter service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
syntax = "proto3"; // 使用proto3解读
// 枚举类型
// OneOf 声明一个区间,只能使用此区间内部某一个具体值类型
message Person {
oneof TestOneOf {
string one = 2;
string two = 3;
}
}
// 导入定义
import "grpc_class/hello_grpc/test.proto";
// 定义服务
service ServiceName {
rpc FunName(Request) returns(Response); // 传统的及时响应
}